This repository has been archived by the owner on Jul 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.yaml
206 lines (192 loc) · 6.65 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
workshop-lambda
workshop of Gert with Lambda
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Runtime: python3.6
Timeout: 5
MemorySize: 128
AutoPublishAlias: live # More info about Safe Deployments: https://github.com/awslabs/serverless-application-model/blob/master/docs/safe_lambda_deployments.rst
Tracing: Active
DeploymentPreference:
Type: Canary10Percent5Minutes
Resources:
ApiGateway:
Type: AWS::Serverless::Api
Properties:
Name: workshop-lambda
DefinitionUri: swagger.yaml
StageName: Prod
EndpointConfiguration: REGIONAL
Variables:
Region: !Ref AWS::Region
AccountId: !Ref AWS::AccountId
ApidocsUrl: s3-eu-west-1.amazonaws.com/workshop-tim/workshop-lambda/docs/index.html
MethodSettings:
- MetricsEnabled: True
LoggingLevel: INFO
ResourcePath: "/"
HttpMethod: "*"
DataTraceEnabled: True
LambdaOneFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: /aws/lambda/lambda-one-cfn
RetentionInDays: 7
LambdaOneFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
FunctionName: lambda-one-cfn
Handler: my_module/lambda_one.lambda_handler
CodeUri: build/
Events:
GetResource:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
RestApiId: !Ref ApiGateway
Path: /rest/one
Method: GET
Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
Variables:
PARAM1: VALUE
DeploymentPreference:
Type: AllAtOnce
Alarms:
- !Ref LambdaOneErrorAlarm
- !Ref LambdaOneLiveErrorAlarm
Hooks:
PreTraffic: !Ref PreTrafficLambdaOneFunction
LambdaOneErrorAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: errors on lambda one
AlarmName: Check-Lambda-One-Errors
ActionsEnabled: True
ComparisonOperator: GreaterThanThreshold
EvaluationPeriods: 1
Namespace: AWS/Lambda
MetricName: Errors
Dimensions:
- Name: FunctionName
Value: !Ref LambdaOneFunction
- Name: Resource
Value: !Ref LambdaOneFunction
Period: 60
Statistic: Sum
Threshold: 0
TreatMissingData: notBreaching
LambdaOneLiveErrorAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: errors on lambda one live alias
AlarmName: Check-Lambda-One-Live-Errors
ActionsEnabled: True
ComparisonOperator: GreaterThanThreshold
EvaluationPeriods: 1
Namespace: AWS/Lambda
MetricName: Errors
Dimensions:
- Name: FunctionName
Value: !Ref LambdaOneFunction
- Name: Resource
Value: !Join [ ':', [ !Ref LambdaOneFunction, 'live' ] ]
Period: 60
Statistic: Sum
Threshold: 0
TreatMissingData: notBreaching
PreTrafficLambdaOneFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: CodeDeployHook_lamda-one-pre-traffic-cfn
Handler: my_module/lambda_one_pre_traffic_hook.handler
CodeUri: build/
DeploymentPreference:
Enabled: false
# Sample policy to add additional permissions to your Lambda
LambdaOnePreHookAdditionalPermission:
Type: AWS::IAM::Policy
Properties:
PolicyName: root
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- lambda:InvokeFunction
- codedeploy:PutLifecycleEventHookExecutionStatus
Resource: "*"
Roles:
- !Ref PreTrafficLambdaOneFunctionRole # Sample policy to demonstrate Implicit IAM Role created with SAM
LambdaTwoFunctionLogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: /aws/lambda/lambda-two-cfn
RetentionInDays: 7
LambdaTwoFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
FunctionName: lambda-two-cfn
Handler: my_module/lambda_two.lambda_handler
CodeUri: build/
Events:
GetResource:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
RestApiId: !Ref ApiGateway
Path: /rest/two
Method: GET
DeploymentPreference:
Alarms:
- !Ref LambdaTwoErrorAlarm
- !Ref LambdaTwoLiveErrorAlarm
LambdaTwoErrorAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: errors on lambda two
AlarmName: Check-Lambda-Two-Errors
ActionsEnabled: True
ComparisonOperator: GreaterThanThreshold
EvaluationPeriods: 1
Namespace: AWS/Lambda
MetricName: Errors
Dimensions:
- Name: FunctionName
Value: !Ref LambdaTwoFunction
- Name: Resource
Value: !Ref LambdaTwoFunction
Period: 60
Statistic: Sum
Threshold: 0
TreatMissingData: notBreaching
LambdaTwoLiveErrorAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: errors on lambda two live alias
AlarmName: Check-Lambda-Two-Live-Errors
ActionsEnabled: True
ComparisonOperator: GreaterThanThreshold
EvaluationPeriods: 1
Namespace: AWS/Lambda
MetricName: Errors
Dimensions:
- Name: FunctionName
Value: !Ref LambdaTwoFunction
- Name: Resource
Value: !Join [ ':', [ !Ref LambdaTwoFunction, 'live' ] ]
Period: 60
Statistic: Sum
Threshold: 0
TreatMissingData: notBreaching
Outputs:
# FirstApigwURL:
# Description: "API Gateway endpoint URL for Prod environment for First Function"
# Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/first/proxy"
LambdaOneFunction:
Description: "Lambda One Function ARN"
Value: !GetAtt LambdaOneFunction.Arn
LambdaTwoFunction:
Description: "Lambda Two Function ARN"
Value: !GetAtt LambdaTwoFunction.Arn