AWSTemplateFormatVersion: "2010-09-09" Transform: AWS::Serverless-2016-10-31 Description: "backend Sample SAM Template for backend " Parameters: BucketName: Type: String DomainName: Type: String OpenSearchURL: Type: String SagemakerEndpoint: Type: String LambdaCodeFile: Type: String Globals: Function: Timeout: 60 MemorySize: 512 Api: Cors: AllowMethods: "'*'" AllowHeaders: "'*'" AllowOrigin: "'*'" Resources: PostFetchSimilarPhotosLambda: Type: AWS::Serverless::Function Properties: CodeUri: Bucket: !Ref BucketName Key: !Ref LambdaCodeFile Handler: app.lambda_handler Runtime: python3.8 Environment: Variables: ES_ENDPOINT: !Ref OpenSearchURL SM_ENDPOINT: !Ref SagemakerEndpoint Policies: - Version: "2012-10-17" Statement: - Sid: AllowSagemakerInvokeEndpoint Effect: Allow Action: - sagemaker:InvokeEndpoint Resource: !Sub arn:aws:sagemaker:${AWS::Region}:${AWS::AccountId}:endpoint/${SagemakerEndpoint} - Version: "2012-10-17" Statement: - Sid: AllowESS Effect: Allow Action: - es:* Resource: !Sub arn:aws:es:${AWS::Region}:${AWS::AccountId}:domain/${DomainName}/* - S3ReadPolicy: BucketName: !Ref BucketName Events: PostURL: Type: Api Properties: Path: /postURL Method: post PostImage: Type: Api Properties: Path: /postImage Method: post Outputs: ImageSimilarityApi: Description: API Gateway endpoint URL for Prod stage for fetchPhoto function Value: !Sub https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/ PostFetchSimilarPhotosLambda: Description: Lambda Function ARN Value: !GetAtt PostFetchSimilarPhotosLambda.Arn