Interactive Reference Architecture
Click on the components or numbered steps below to explore how this architecture works.
This is the most basic of patterns you’re likely to see with serverless applications. The Simple Web Service fronts a Lambda function with an API Gateway. I’ve shown DynamoDB as the database here because it scales nicely with the high concurrency capabilities of Lambda.
Deploy this Pattern
Below are the basic configurations for deploying this pattern using different frameworks and platforms. Additional configuration for your environment will be necessary. The source files and additional examples are available in the GitHub repo.
-
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960service: simple-web-serviceprovider:name: awsruntime: nodejs12.xstage: ${opt:stage,'dev'}region: us-east-1stackName: ${self:service}-${self:provider.stage}stackTags:SERVICE: ${self:service}httpApi:payload: '2.0'cors: truefunctions:GetUser:handler: index.handlermemorySize: 1024timeout: 6tracing: Activeenvironment:TABLE_NAME: !Ref UsersTABLE_ARN: !GetAtt Users.ArniamRoleStatementsName: ${self:service}-${self:provider.stage}-getuser-roleiamRoleStatements:- Effect: AllowAction:- dynamodb:getItem- dynamodb:putItem- dynamodb:updateItem- dynamodb:deleteItemResource:- !Join [ '/', [ !GetAtt Users.Arn, '*' ] ]- !GetAtt Users.Arn- Effect: AllowAction:- xray:PutTraceSegments- xray:PutTelemetryRecordsResource: "*"events:- httpApi:path: /user/{id}method: getplugins:- serverless-iam-roles-per-functionresources:Resources:Users:Type: AWS::DynamoDB::TableProperties:AttributeDefinitions:- AttributeName: idAttributeType: SBillingMode: PAY_PER_REQUESTKeySchema:- AttributeName: idKeyType: HASHStreamSpecification:StreamViewType: NEW_AND_OLD_IMAGES
-
12345678910111213141516171819202122232425262728293031323334// Full example: https://github.com/jeremydaly/reference-architectures/tree/master/simple-web-service/pulumiimport * as aws from "@pulumi/aws";import * as awsx from "@pulumi/awsx";// Provision a DynamoDB Table.const users = new aws.dynamodb.Table("users", {attributes: [{name: "id",type: "S",}],hashKey: "id",billingMode: "PAY_PER_REQUEST",streamViewType: "NEW_AND_OLD_IMAGES",});// Create an API Gateway with a single /user/{id} route that uses the Table.// This uses the default Lambda, IAM, and name settings; for full control over// them, see the aws.lambda.CallbackFunction class, which can be allocated// separately and passed instead of the inline eventHandler below.const api = new awsx.apigateway.API("api", {routes: [{path: "/user/{id}",method: "GET",eventHandler: async (event, context) => {const tableName = users.name.get();const tableArn = users.arn.get();return { statusCode: 200, body: JSON.stringify(event) };},}]});// Export the resulting API Gateway URL:export const url = api.url;
-
Are you a CDK Guru?
Would you like to contribute patterns to the community?
Check out the Github repo!
Want to Contribute?
All patterns and sample code are free to use and available under the MIT License. If you'd like to contribute to these patterns, please submit PRs to the GitHub repo.
» Explore more Serverless Reference Architectures and Patterns
Nice !
I am curious to know: how did you create your interactive architecture diagram ? Did you implement it by yourself or with a 3rd party tool/lib ?
Thanks for sharing !