AWSTemplateFormatVersion: "2010-09-09" Description: Template generated by rain Transform: AWS::Serverless-2016-10-31 Parameters: DataBucket: Type: String DataPrefix: Type: String Resources: Queue: Type: "AWS::SQS::Queue" Properties: VisibilityTimeout: 300 QueuePolicy: Type: "AWS::SQS::QueuePolicy" Properties: Queues: - !Ref Queue PolicyDocument: Statement: Effect: Allow Principal: Service: s3.amazonaws.com Action: - sqs:SendMessage Resource: !GetAtt Queue.Arn Condition: ArnLike: aws:SourceArn: !Sub arn:aws:s3:::${DataBucket} ConfigureDataBucketRole: Type: "AWS::IAM::Role" Properties: AssumeRolePolicyDocument: Statement: - Effect: Allow Principal: Service: lambda.amazonaws.com Action: - "sts:AssumeRole" ManagedPolicyArns: - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" Policies: - PolicyName: allow-s3-notification-config PolicyDocument: Statement: Effect: Allow Action: - s3:GetBucketNotification - s3:PutBucketNotification Resource: !Sub arn:aws:s3:::${DataBucket} ConfigureDataBucketFunction: Type: "AWS::Lambda::Function" Properties: Code: ../src/lambda Handler: bucket.handler Runtime: nodejs12.x Role: !GetAtt ConfigureDataBucketRole.Arn Environment: Variables: StackName: !Ref AWS::StackName ConfigureDataBucket: Type: "AWS::CloudFormation::CustomResource" Properties: ServiceToken: !GetAtt ConfigureDataBucketFunction.Arn BucketName: !Ref DataBucket Prefix: !Ref DataPrefix QueueArn: !GetAtt Queue.Arn Table: Type: "AWS::DynamoDB::Table" Properties: KeySchema: - AttributeName: PK KeyType: HASH - AttributeName: SK KeyType: RANGE AttributeDefinitions: - AttributeName: PK AttributeType: S - AttributeName: SK AttributeType: S - AttributeName: TK AttributeType: 'N' GlobalSecondaryIndexes: - IndexName: GSI1 KeySchema: - AttributeName: SK KeyType: HASH - AttributeName: TK KeyType: RANGE Projection: ProjectionType: ALL BillingMode: PAY_PER_REQUEST IndexFunction: Type: "AWS::Serverless::Function" Properties: CodeUri: ../src/lambda Handler: index.handler Timeout: 300 Environment: Variables: TableName: !Ref Table Events: QueueEvent: Type: SQS Properties: Queue: !GetAtt Queue.Arn Policies: - DynamoDBCrudPolicy: TableName: !Ref Table - S3ReadPolicy: BucketName: !Ref DataBucket Runtime: nodejs12.x Outputs: TableName: Value: !Ref Table