AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: Serverless patterns - Amazon API Gateway to AWS Lambda to Amazon DynamoDB Parameters: DynamoDBTableName: Type: String Default: DemoStreamDynamoDBToLambda Description: Enter a name for the Kinesis Data Stream. Resources: ProducerFunction: Type: AWS::Serverless::Function Properties: FunctionName: ProducerFunction Handler: apiHandler.lambda_handler Runtime: python3.9 CodeUri: src/ Policies: DynamoDBCrudPolicy: TableName: !Ref DynamoDBTable Events: ApiEvent: Type: Api Properties: Path: / Method: POST DynamoDBTable: Type: AWS::DynamoDB::Table Properties: AttributeDefinitions: - AttributeName: id AttributeType: S KeySchema: - AttributeName: id KeyType: HASH ProvisionedThroughput: ReadCapacityUnits: 5 WriteCapacityUnits: 5 StreamSpecification: StreamViewType: NEW_IMAGE TableName: !Ref DynamoDBTableName ConsumerFunction: Type: AWS::Serverless::Function Properties: FunctionName: ConsumerFunction Handler: messageHandler.lambda_handler Runtime: python3.9 CodeUri: src/ Policies: - DynamoDBStreamReadPolicy: TableName: !Ref DynamoDBTableName StreamName: !Select [3, !Split ["/", !GetAtt DynamoDBTable.StreamArn]] Events: Stream: Type: DynamoDB Properties: Stream: !GetAtt DynamoDBTable.StreamArn StartingPosition: LATEST BatchSize: 100 Outputs: EndpointUrl: Description: 'HTTP REST endpoint URL' Value: !Sub 'https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod'