AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: > {{ cookiecutter.project_name }} Globals: # https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-template-anatomy-globals.html Api: EndpointConfiguration: REGIONAL TracingEnabled: true Cors: # https://awslabs.github.io/aws-lambda-powertools-python/latest/core/event_handler/api_gateway/#cors # AllowOrigin: "'https://example.com'" AllowOrigin: "'*'" # Dev only AllowHeaders: "'Content-Type,Authorization,X-Amz-Date'" MaxAge: "'300'" BinaryMediaTypes: # https://awslabs.github.io/aws-lambda-powertools-python/latest/core/event_handler/api_gateway/#binary-responses - '*~1*' # converts to */* for any binary type Function: Timeout: 5 MemorySize: 256 Runtime: python3.9 Tracing: Active # https://docs.aws.amazon.com/lambda/latest/dg/lambda-x-ray.html {%- if cookiecutter.include_safe_deployment == "y" %} AutoPublishAlias: live # More info about Safe Deployments: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-deploymentpreference.html DeploymentPreference: Type: Linear10PercentEvery1Minute {% endif %} # Embed Lambda Powertools as a shared Layer # See: https://awslabs.github.io/aws-lambda-powertools-python/latest/#lambda-layer Layers: # - !Sub arn:aws:lambda:${AWS::Region}:017000801446:layer:AWSLambdaPowertoolsPython:9 Environment: Variables: # Powertools env vars: https://awslabs.github.io/aws-lambda-powertools-python/#environment-variables LOG_LEVEL: INFO POWERTOOLS_LOGGER_SAMPLE_RATE: 0.1 POWERTOOLS_LOGGER_LOG_EVENT: true POWERTOOLS_METRICS_NAMESPACE: MyServerlessApplication POWERTOOLS_SERVICE_NAME: hello Resources: HelloWorldFunction: Type: AWS::Serverless::Function # More info about Function Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html Properties: Handler: app.lambda_handler CodeUri: hello_world Description: Hello World function Events: HelloPath: Type: Api # More info about API Event Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-api.html Properties: Path: /hello Method: GET HelloYou: Type: Api Properties: Path: /hello/{name} Method: GET # Policies: # Example inline policy # - Version: "2012-10-17" # Statement: # - Effect: "Allow" # Action: # - "ssm:GetParameter" # Resource: # - "*" Environment: Variables: PARAM1: VALUE Tags: LambdaPowertools: python # Sample policy to add additional permissions to your Lambda # HelloWorldFunctionAdditionalPermission: # Type: "AWS::IAM::Policy" # Properties: # PolicyName: "root" # PolicyDocument: # Version: "2012-10-17" # Statement: # - # Effect: "Allow" # Action: "ssm:GetParameters" # Resource: "*" # Roles: # - !Ref HelloWorldFunctionRole # Sample policy to demonstrate Implicit IAM Role created with SAM Outputs: HelloWorldApigwURL: Description: "API Gateway endpoint URL for Prod environment for Hello World Function" Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello" HelloWorldFunction: Description: "Hello World Lambda Function ARN" Value: !GetAtt HelloWorldFunction.Arn