Transform: 'AWS::Serverless-2016-10-31' Parameters: BucketName: Type: "String" LambdaCode: Type: "String" Default: "heart_function-1.0.0.jar" SageMakerEndpoint: Type: "String" Email: Type: String Resources: LambdaFunctionHandler: # This resource creates a Lambda function. Type: 'AWS::Serverless::Function' Properties: Description: Lambda handler that calls SageMaker for heat disease prediction # Time out value to 15 seconds Timeout: 30 # Initial Memory size MemorySize: 512 # The location of the Lambda function code. CodeUri: #!Ref function allows you to fetch value #of parameters and other resources at runtime Bucket: !Ref BucketName Key: !Ref LambdaCode # This function uses Java8 runtime. Runtime: java8 # This is the Lambda function's handler. Handler: com.amazonaws.samples.heartfunction.LambdaFunctionHandler #Lambda enviornment variables Environment: Variables: SAGEMAKER_ENDPOINT: !Ref SageMakerEndpoint TOPIC_ARN: !Ref MySNSTopic Policies: - AWSLambdaExecute # Managed Policy - Version: '2012-10-17' # Policy Document Statement: #- Allow access to SageMaker and SNS - Effect: Allow Action: - sagemaker:* - sns:Publish Resource: "*" # Event sources to attach to this function. In this case, we are attaching # one API Gateway endpoint to the Lambda function. The function is # called when a HTTP request is made to the API Gateway endpoint. Events: HeartDiseaseApi: # Define an API Gateway endpoint that responds to HTTP POST at /predict-heart-disease Type: Api Properties: RestApiId: !Ref ApiGatewayApi Path: /predict-heart-disease Method: POST ApiGatewayApi: Type: AWS::Serverless::Api Properties: StageName: Prod Variables: LambdaFunctionName: !Ref LambdaFunctionHandler MySNSTopic: Type: AWS::SNS::Topic Properties: Subscription: - Endpoint: !Ref Email Protocol: email Outputs: ProdDataEndpoint: Description: "API Prod stage endpoint" Value: !Sub "https://${ApiGatewayApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/predict-heart-disease"