AWSTemplateFormatVersion: "2010-09-09" Transform: AWS::Serverless-2016-10-31 Description: Happy Path - Example workflow 4 Parameters: ApplicationTableName: Type: String Description: Name of application's DynamoDB table Default: hp-application S3UploadBucketName: Type: String Description: The name for the S3 upload bucket. Default: 'happy-path-upload' S3DistributionBucketName: Type: String Description: The name for the S3 upload bucket. Default: 'happy-path-distribution' StreamARN: Type: String Description: The ARN for the DynamoDB table stream. Default: 'arn:aws:dynamodb:us-east-1:123456789012:table/hp-application/stream/2020-06-29T14:29:10.716' SharpLayerARN: Type: String Description: The ARN for the Sharp Lambda Layer. Default: 'arn:aws:lambda:us-east-1:763653534548:layer:node-sharp:3' Globals: Function: Timeout: 5 Runtime: nodejs12.x Tags: Application: HappyPath Resources: #Lambda functions ResizerFunction: Type: AWS::Serverless::Function Properties: CodeUri: ../../functions/resizer/ Handler: app.handler MemorySize: 2056 Layers: - !Ref SharpLayerARN Environment: Variables: OutputBucket: !Ref S3DistributionBucketName TableName: !Ref ApplicationTableName Policies: - S3ReadPolicy: BucketName: !Ref S3UploadBucketName - S3CrudPolicy: BucketName: !Ref S3DistributionBucketName - DynamoDBWritePolicy: TableName: !Ref ApplicationTableName PublishFunction: Type: AWS::Serverless::Function Properties: CodeUri: ../../functions/publish/ Handler: app.handler MemorySize: 128 Layers: - !Ref SharpLayerARN Environment: Variables: TableName: !Ref ApplicationTableName Policies: - DynamoDBWritePolicy: TableName: !Ref ApplicationTableName ModeratorFunction: Type: AWS::Serverless::Function Properties: CodeUri: ../../functions/analyze/moderator Handler: app.handler MemorySize: 128 Timeout: 10 Policies: - S3ReadPolicy: BucketName: !Ref S3UploadBucketName - RekognitionLabelsPolicy: {} DimensionsFunction: Type: AWS::Serverless::Function Properties: CodeUri: ../../functions/analyze/dimensions Handler: app.handler MemorySize: 128 Environment: Variables: minPixels: 500 allowedTypes: 'jpg' Policies: - S3ReadPolicy: BucketName: !Ref S3UploadBucketName LabelsFunction: Type: AWS::Serverless::Function Properties: CodeUri: ../../functions/analyze/people Handler: app.handler MemorySize: 128 Timeout: 10 Policies: - S3ReadPolicy: BucketName: !Ref S3UploadBucketName - RekognitionLabelsPolicy: {} # Step Functions state machine v4StateMachine: Type: AWS::Serverless::StateMachine Properties: DefinitionUri: ../../statemachines/v4.asl.json DefinitionSubstitutions: ResizerFunctionArn: !GetAtt ResizerFunction.Arn PublishFunctionArn: !GetAtt PublishFunction.Arn ModeratorFunctionArn: !GetAtt ModeratorFunction.Arn DimensionsFunctionArn: !GetAtt DimensionsFunction.Arn LabelsFunctionArn: !GetAtt LabelsFunction.Arn DDBGetItem: !Sub arn:${AWS::Partition}:states:::dynamodb:getItem DDBUpdateItem: !Sub arn:${AWS::Partition}:states:::dynamodb:updateItem DDBTable: !Ref ApplicationTableName Events: UploadComplete: Type: EventBridgeRule Properties: Pattern: source: - custom.happyPath detail-type: - uploadComplete Policies: # Find out more about SAM policy templates: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-policy-templates.html - LambdaInvokePolicy: FunctionName: !Ref ResizerFunction - LambdaInvokePolicy: FunctionName: !Ref PublishFunction - LambdaInvokePolicy: FunctionName: !Ref ModeratorFunction - LambdaInvokePolicy: FunctionName: !Ref DimensionsFunction - LambdaInvokePolicy: FunctionName: !Ref LabelsFunction - DynamoDBCrudPolicy: TableName: !Ref ApplicationTableName