--- AWSTemplateFormatVersion: '2010-09-09' Description: 'Stack to setup environment for Textract-Comprehend workshop' Resources: ElasticLibs: Type: "AWS::Lambda::LayerVersion" Properties: CompatibleRuntimes: - python3.7 Content: S3Bucket: !Join - "-" - - "aws-textract-workshop" - !Ref 'AWS::Region' S3Key: bootstrap/elasticlibs.zip Description: Layer for elasticsearch libraries (elasticsearch, aws-requests-auth, requests-aws4auth) LayerName: ElasticLibs LicenseInfo: Apache2 InputS3Bucket: Type: AWS::S3::Bucket Properties: BucketName: !Join - "-" - - "workshop-textract" - !Select [0, !Split ["-", !Select [2, !Split ["/", !Ref "AWS::StackId"]]]] LambdaExecutionRole: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: - lambda.amazonaws.com Action: - sts:AssumeRole Path: "/" ManagedPolicyArns: - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" Policies: - PolicyName: s3policy PolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Action: - s3:get* Resource: !Join - '' - - 'arn:aws:s3:::' - !Ref InputS3Bucket - /* - PolicyName: textractpolicy PolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Action: - textract:* Resource: "*" DocumentTextract: Type: AWS::Lambda::Function Properties: Description: Lambda function in charge of launching Textract FunctionName: !Join - "-" - - "documentTextract" - !Select [0, !Split ["-", !Select [2, !Split ["/", !Ref "AWS::StackId"]]]] Handler: index.handler MemorySize: 128 Role: !GetAtt LambdaExecutionRole.Arn Runtime: python3.7 Timeout: 300 Code: ZipFile: | import json def handler(event, context): # TODO: Replace with code to call textract response = { 'statusCode': 200, 'body': json.dumps('Hello!') } return response Outputs: InputS3Bucket: Description: Name of the input bucket Value: !Ref InputS3Bucket DocumentTextractFunction: Description: Function that will be triggered when a document is uploaded in the input bucket Value: !Ref DocumentTextract