AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: 'backend Sample SAM Template for backend ' Parameters: BucketName: Type: String DomainName: Type: String ElasticSearchURL: Type: String SagemakerEndpoint: Type: String Globals: Function: Timeout: 60 MemorySize: 512 Api: Cors: AllowMethods: '''*''' AllowHeaders: '''*''' AllowOrigin: '''*''' Resources: PostGetSimilarTextFunction: Type: AWS::Serverless::Function Properties: CodeUri: s3://aws-ml-blog/artifacts/nlu-search/lambda.zip Handler: app.lambda_handler Runtime: python3.7 Environment: Variables: ES_ENDPOINT: Ref: ElasticSearchURL SM_ENDPOINT: Ref: SagemakerEndpoint Policies: - Version: '2012-10-17' Statement: - Sid: AllowSagemakerInvokeEndpoint Effect: Allow Action: - sagemaker:InvokeEndpoint Resource: - Fn::Sub: arn:aws:sagemaker:${AWS::Region}:${AWS::AccountId}:endpoint/${SagemakerEndpoint} - Version: '2012-10-17' Statement: - Sid: AllowESS Effect: Allow Action: - es:* Resource: - Fn::Sub: arn:aws:es:${AWS::Region}:${AWS::AccountId}:domain/${DomainName}/* - S3ReadPolicy: BucketName: Ref: BucketName Events: PostText: Type: Api Properties: Path: /postText Method: post PostMatch: Type: Api Properties: Method: post Path: /postMatch Outputs: TextSimilarityApi: Description: API Gateway endpoint URL for Prod stage for GetSimilarText function Value: Fn::Sub: https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/ PostGetSimilarTextFunctionArn: Description: GetSimilarText Lambda Function ARN Value: Fn::GetAtt: - PostGetSimilarTextFunction - Arn PostGetSimilarTextLambdaIamRole: Description: Implicit IAM Role created for GetSimilarText function Value: Fn::GetAtt: - PostGetSimilarTextFunction - Arn