-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
86 lines (80 loc) · 3.67 KB
/
template.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
pt-issue-520
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.8
Tracing: Active # https://docs.aws.amazon.com/lambda/latest/dg/lambda-x-ray.html
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:
Accounts:
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: /accounts/{account_id}
Method: GET
AccountSourceNetworks:
Type: Api
Properties:
Path: /accounts/{account_id}/source_networks
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