-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.yaml
101 lines (94 loc) · 4.2 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Identity Function is a Lambda Function that returns the same value that was provided as its argument - but compiled!
It exposes an API that can be invoked with code of a Lambda function, and returns the archive with the executable.
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: 900
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:
WorkflowGoLayer:
Type: AWS::Serverless::LayerVersion
Properties:
ContentUri: layers
Metadata:
BuildMethod: makefile
IdentityFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html
Properties:
Layers:
- !Ref WorkflowGoLayer
Handler: app.lambda_handler
CodeUri: identity
Description: Identity Function
Events:
BuildPath:
Type: Api
Properties:
Path: /build
Method: POST
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
# IdentityFunctionAdditionalPermission:
# Type: "AWS::IAM::Policy"
# Properties:
# PolicyName: "root"
# PolicyDocument:
# Version: "2012-10-17"
# Statement:
# -
# Effect: "Allow"
# Action: "ssm:GetParameters"
# Resource: "*"
# Roles:
# - !Ref IdentityFunctionRole # Sample policy to demonstrate Implicit IAM Role created with SAM
Outputs:
IdentityApigwURL:
Description: "API Gateway endpoint URL for Prod environment for Identity Function"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello"
IdentityFunction:
Description: "Identity Lambda Function ARN"
Value: !GetAtt IdentityFunction.Arn