TheArchitect

Serverless API

AWS architecture template · API Gateway → Lambda → DynamoDB + SNS

Serverless API is a free AWS architecture template built with API Gateway, CloudWatch, DynamoDB, IAM, Lambda and SNS. Open it in TheArchitect to edit the diagram, estimate monthly cost, and export the CloudFormation or Terraform that deploys it.

API GatewayLambdaLambda RoleItems TableEvent TopicError Alarm
Serverless API architecture diagram

AWS services in this template

  • API Gateway
  • CloudWatch
  • DynamoDB
  • IAM
  • Lambda
  • SNS

Deployment notes

Deploy-ready

  • Includes inline demo Lambda code, an execution role, API Gateway integration, and realistic event/data settings.

Generated CloudFormation — 8 resources

Logical IDResource type
APIGatewayapigatewayAWS::ApiGateway::RestApi
LambdalambdaAWS::Lambda::Function
LambdaRoleiamAWS::IAM::Role
ItemsTabledynamodbAWS::DynamoDB::Table
EventTopicsnsAWS::SNS::Topic
ErrorAlarmcloudwatchAWS::CloudWatch::Alarm
LambdalambdaEventTopicsnsPermissionAWS::Lambda::Permission
EventTopicsnsLambdalambdaSubscriptionAWS::SNS::Subscription
View the full CloudFormation template
{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Description": "Generated by TheArchitect — https://www.thecloudarchitect.dev",
  "Metadata": {
    "TheArchitect": {
      "Edges": [
        {
          "From": "LambdaRoleiam",
          "To": "Lambdalambda",
          "Label": "role"
        },
        {
          "From": "Lambdalambda",
          "To": "ItemsTabledynamodb",
          "Label": "read/write"
        },
        {
          "From": "Lambdalambda",
          "To": "EventTopicsns",
          "Label": "events"
        },
        {
          "From": "Lambdalambda",
          "To": "ErrorAlarmcloudwatch",
          "Label": "logs"
        }
      ]
    }
  },
  "Resources": {
    "APIGatewayapigateway": {
      "Type": "AWS::ApiGateway::RestApi",
      "Properties": {
        "Name": "architect-demo-api",
        "Description": "Regional REST API for demo application requests.",
        "EndpointConfiguration": {
          "Types": [
            "REGIONAL"
          ]
        },
        "MinimumCompressionSize": 1024
      }
    },
    "Lambdalambda": {
      "Type": "AWS::Lambda::Function",
      "DependsOn": [
        "LambdaRoleiam"
      ],
      "Properties": {
        "FunctionName": "architect-demo-api-handler",
        "Runtime": "nodejs20.x",
        "Handler": "index.handler",
        "MemorySize": 512,
        "Architectures": [
          "arm64"
        ],
        "Timeout": 30,
        "Description": "Handles API requests and publishes application events.",
        "Environment": {
          "Variables": {
            "APP_ENV": "demo",
            "LOG_LEVEL": "info"
          }
        },
        "TracingConfig": {
          "Mode": "Active"
        },
        "Code": {
          "ZipFile": "exports.handler = async (event) => ({ statusCode: 200, body: JSON.stringify({ ok: true, requestId: event.requestContext?.requestId || 'demo' }) });"
        },
        "Role": {
          "Fn::GetAtt": [
            "LambdaRoleiam",
            "Arn"
          ]
        }
      }
    },
    "LambdaRoleiam": {
      "Type": "AWS::IAM::Role",
      "Properties": {
        "RoleName": "architect-demo-api-exec-role",
        "Description": "Execution role for the serverless API handler.",
        "AssumeRolePolicyDocument": {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Effect": "Allow",
              "Principal": {
                "Service": "lambda.amazonaws.com"
              },
              "Action": "sts:AssumeRole"
            }
          ]
        },
        "ManagedPolicyArns": [
          "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
        ]
      }
    },
    "ItemsTabledynamodb": {
      "Type": "AWS::DynamoDB::Table",
      "Properties": {
        "TableName": "architect-demo-items",
        "BillingMode": "PAY_PER_REQUEST",
        "AttributeDefinitions": [
          {
            "AttributeName": "pk",
            "AttributeType": "S"
          },
          {
            "AttributeName": "sk",
            "AttributeType": "S"
          }
        ],
        "KeySchema": [
          {
            "AttributeName": "pk",
            "KeyType": "HASH"
          },
          {
            "AttributeName": "sk",
            "KeyType": "RANGE"
          }
        ],
        "PointInTimeRecoverySpecification": {
          "PointInTimeRecoveryEnabled": true
        },
        "SSESpecification": {
          "SSEEnabled": true
        }
      }
    },
    "EventTopicsns": {
      "Type": "AWS::SNS::Topic",
      "Properties": {
        "TopicName": "architect-demo-events",
        "DisplayName": "Architect demo events"
      }
    },
    "ErrorAlarmcloudwatch": {
      "Type": "AWS::CloudWatch::Alarm",
      "Properties": {
        "AlarmName": "architect-demo-api-errors",
        "AlarmDescription": "Demo alarm for API Lambda errors.",
        "Namespace": "AWS/Lambda",
        "MetricName": "Errors",
        "Statistic": "Sum",
        "Period": 60,
        "EvaluationPeriods": 1,
        "Threshold": 1,
        "ComparisonOperator": "GreaterThanOrEqualToThreshold",
        "TreatMissingData": "notBreaching"
      }
    },
    "LambdalambdaEventTopicsnsPermission": {
      "Type": "AWS::Lambda::Permission",
      "DependsOn": [
        "Lambdalambda",
        "EventTopicsns"
      ],
      "Properties": {
        "Action": "lambda:InvokeFunction",
        "FunctionName": {
          "Ref": "Lambdalambda"
        },
        "Principal": "sns.amazonaws.com",
        "SourceArn": {
          "Ref": "EventTopicsns"
        }
      }
    },
    "EventTopicsnsLambdalambdaSubscription": {
      "Type": "AWS::SNS::Subscription",
      "DependsOn": [
        "LambdalambdaEventTopicsnsPermission"
      ],
      "Properties": {
        "TopicArn": {
          "Ref": "EventTopicsns"
        },
        "Protocol": "lambda",
        "Endpoint": {
          "Fn::GetAtt": [
            "Lambdalambda",
            "Arn"
          ]
        }
      }
    }
  }
}

Generated by TheArchitect from the diagram above. Review values such as names, CIDR ranges and instance sizes before deploying to your account.

Related templates