Skip to content

Commit e00c7aa

Browse files
kverma23davidgf
authored andcommitted
added support for cloudwatch events based triggers (#49)
* Added support for CloudWatch Events based triggers * Added integration test for CloudWatch based event triggers
1 parent cec1db1 commit e00c7aa

11 files changed

+898
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 0.4.6 (14.02.2019)
2+
- Add support for CloudWatchEvents
3+
14
# 0.4.5 (14.01.2019)
25
- Allow configuring CodeDeploy triggers
36

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ The plugin relies on the [AWS Lambda traffic shifting feature](https://docs.aws.
9797

9898
## Limitations
9999

100-
For now, the plugin only works with Lambda functions invoked by API Gateway, Stream based (such as the triggered by Kinesis or DynamoDB Streams), SNS based events and S3 events. More events will be added soon.
100+
For now, the plugin only works with Lambda functions invoked by API Gateway, Stream based (such as the triggered by Kinesis or DynamoDB Streams), SNS based events, S3 events and CloudWatch events. More events will be added soon.
101101

102102
## License
103103

Lines changed: 327 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,327 @@
1+
{
2+
"AWSTemplateFormatVersion": "2010-09-09",
3+
"Description": "The AWS CloudFormation template for this Serverless application",
4+
"Resources": {
5+
"ServerlessDeploymentBucket": {
6+
"Type": "AWS::S3::Bucket"
7+
},
8+
"HelloLogGroup": {
9+
"Type": "AWS::Logs::LogGroup",
10+
"Properties": {
11+
"LogGroupName": "/aws/lambda/canary-deployments-test-dev-hello"
12+
}
13+
},
14+
"PreHookLogGroup": {
15+
"Type": "AWS::Logs::LogGroup",
16+
"Properties": {
17+
"LogGroupName": "/aws/lambda/canary-deployments-test-dev-preHook"
18+
}
19+
},
20+
"PostHookLogGroup": {
21+
"Type": "AWS::Logs::LogGroup",
22+
"Properties": {
23+
"LogGroupName": "/aws/lambda/canary-deployments-test-dev-postHook"
24+
}
25+
},
26+
"IamRoleLambdaExecution": {
27+
"Type": "AWS::IAM::Role",
28+
"Properties": {
29+
"AssumeRolePolicyDocument": {
30+
"Version": "2012-10-17",
31+
"Statement": [
32+
{
33+
"Effect": "Allow",
34+
"Principal": {
35+
"Service": [
36+
"lambda.amazonaws.com"
37+
]
38+
},
39+
"Action": [
40+
"sts:AssumeRole"
41+
]
42+
}
43+
]
44+
},
45+
"Policies": [
46+
{
47+
"PolicyName": {
48+
"Fn::Join": [
49+
"-",
50+
[
51+
"dev",
52+
"canary-deployments-test",
53+
"lambda"
54+
]
55+
]
56+
},
57+
"PolicyDocument": {
58+
"Version": "2012-10-17",
59+
"Statement": [
60+
{
61+
"Effect": "Allow",
62+
"Action": [
63+
"logs:CreateLogStream"
64+
],
65+
"Resource": [
66+
{
67+
"Fn::Sub": "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/canary-deployments-test-dev-hello:*"
68+
},
69+
{
70+
"Fn::Sub": "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/canary-deployments-test-dev-preHook:*"
71+
},
72+
{
73+
"Fn::Sub": "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/canary-deployments-test-dev-postHook:*"
74+
}
75+
]
76+
},
77+
{
78+
"Effect": "Allow",
79+
"Action": [
80+
"logs:PutLogEvents"
81+
],
82+
"Resource": [
83+
{
84+
"Fn::Sub": "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/canary-deployments-test-dev-hello:*:*"
85+
},
86+
{
87+
"Fn::Sub": "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/canary-deployments-test-dev-preHook:*:*"
88+
},
89+
{
90+
"Fn::Sub": "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/canary-deployments-test-dev-postHook:*:*"
91+
}
92+
]
93+
},
94+
{
95+
"Effect": "Allow",
96+
"Action": [
97+
"codedeploy:*"
98+
],
99+
"Resource": [
100+
"*"
101+
]
102+
}
103+
]
104+
}
105+
}
106+
],
107+
"Path": "/",
108+
"RoleName": {
109+
"Fn::Join": [
110+
"-",
111+
[
112+
"canary-deployments-test",
113+
"dev",
114+
"us-east-1",
115+
"lambdaRole"
116+
]
117+
]
118+
}
119+
}
120+
},
121+
"HelloLambdaFunction": {
122+
"Type": "AWS::Lambda::Function",
123+
"Properties": {
124+
"Code": {
125+
"S3Bucket": {
126+
"Ref": "ServerlessDeploymentBucket"
127+
},
128+
"S3Key": "serverless/canary-deployments-test/dev/1520191533287-2018-03-04T19:25:33.287Z/canary-deployments-test.zip"
129+
},
130+
"FunctionName": "canary-deployments-test-dev-hello",
131+
"Handler": "handler.hello",
132+
"MemorySize": 1024,
133+
"Role": {
134+
"Fn::GetAtt": [
135+
"IamRoleLambdaExecution",
136+
"Arn"
137+
]
138+
},
139+
"Runtime": "nodejs6.10",
140+
"Timeout": 6
141+
},
142+
"DependsOn": [
143+
"HelloLogGroup",
144+
"IamRoleLambdaExecution"
145+
]
146+
},
147+
"HelloLambdaVersionFYAirphUvjV7H12yGxU1eQrqAiSBMjAi9hdLPgV62L8": {
148+
"Type": "AWS::Lambda::Version",
149+
"DeletionPolicy": "Retain",
150+
"Properties": {
151+
"FunctionName": {
152+
"Ref": "HelloLambdaFunction"
153+
},
154+
"CodeSha256": "sZvdDgxnAbKe1yaQga0XJPD82+o5jFWz+J3lR+q9UHU="
155+
}
156+
},
157+
"PreHookLambdaFunction": {
158+
"Type": "AWS::Lambda::Function",
159+
"Properties": {
160+
"Code": {
161+
"S3Bucket": {
162+
"Ref": "ServerlessDeploymentBucket"
163+
},
164+
"S3Key": "serverless/canary-deployments-test/dev/1520191533287-2018-03-04T19:25:33.287Z/canary-deployments-test.zip"
165+
},
166+
"FunctionName": "canary-deployments-test-dev-preHook",
167+
"Handler": "hooks.pre",
168+
"MemorySize": 1024,
169+
"Role": {
170+
"Fn::GetAtt": [
171+
"IamRoleLambdaExecution",
172+
"Arn"
173+
]
174+
},
175+
"Runtime": "nodejs6.10",
176+
"Timeout": 6
177+
},
178+
"DependsOn": [
179+
"PreHookLogGroup",
180+
"IamRoleLambdaExecution"
181+
]
182+
},
183+
"PreHookLambdaVersionIYyrXlfQM5jjU68REvnAzRxhgq9eoLqSsDjy0": {
184+
"Type": "AWS::Lambda::Version",
185+
"DeletionPolicy": "Retain",
186+
"Properties": {
187+
"FunctionName": {
188+
"Ref": "PreHookLambdaFunction"
189+
},
190+
"CodeSha256": "sZvdDgxnAbKe1yaQga0XJPD82+o5jFWz+J3lR+q9UHU="
191+
}
192+
},
193+
"PostHookLambdaFunction": {
194+
"Type": "AWS::Lambda::Function",
195+
"Properties": {
196+
"Code": {
197+
"S3Bucket": {
198+
"Ref": "ServerlessDeploymentBucket"
199+
},
200+
"S3Key": "serverless/canary-deployments-test/dev/1520191533287-2018-03-04T19:25:33.287Z/canary-deployments-test.zip"
201+
},
202+
"FunctionName": "canary-deployments-test-dev-postHook",
203+
"Handler": "hooks.post",
204+
"MemorySize": 1024,
205+
"Role": {
206+
"Fn::GetAtt": [
207+
"IamRoleLambdaExecution",
208+
"Arn"
209+
]
210+
},
211+
"Runtime": "nodejs6.10",
212+
"Timeout": 6
213+
},
214+
"DependsOn": [
215+
"PostHookLogGroup",
216+
"IamRoleLambdaExecution"
217+
]
218+
},
219+
"PostHookLambdaVersiondh0VUUAh9BrmvORqx3vDEIcHxolKWKCO1YL45mVTbg": {
220+
"Type": "AWS::Lambda::Version",
221+
"DeletionPolicy": "Retain",
222+
"Properties": {
223+
"FunctionName": {
224+
"Ref": "PostHookLambdaFunction"
225+
},
226+
"CodeSha256": "sZvdDgxnAbKe1yaQga0XJPD82+o5jFWz+J3lR+q9UHU="
227+
}
228+
},
229+
"HelloLambdaEventsRuleSchedule1": {
230+
"Type": "AWS::Events::Rule",
231+
"Properties": {
232+
"ScheduleExpression": "rate(1 minute)",
233+
"State": "ENABLED",
234+
"Name": "test-scheduled-event",
235+
"Targets": [
236+
{
237+
"Arn": {
238+
"Fn::GetAtt": [
239+
"HelloLambdaFunction",
240+
"Arn"
241+
]
242+
},
243+
"Id": "testFunctionSchedule"
244+
}
245+
]
246+
}
247+
},
248+
"HelloLambdaPermissionEventsRuleSchedule1": {
249+
"Type": "AWS::Lambda::Permission",
250+
"Properties": {
251+
"FunctionName": {
252+
"Fn::GetAtt": [
253+
"HelloLambdaFunction",
254+
"Arn"
255+
]
256+
},
257+
"Action": "lambda:InvokeFunction",
258+
"Principal": {
259+
"Fn::Join": [
260+
"",
261+
[
262+
"events.",
263+
{
264+
"Ref": "AWS::URLSuffix"
265+
}
266+
]
267+
]
268+
},
269+
"SourceArn": {
270+
"Fn::GetAtt": [
271+
"HelloLambdaEventsRuleSchedule1",
272+
"Arn"
273+
]
274+
}
275+
}
276+
},
277+
"HelloFooAlarm": {
278+
"Type": "AWS::CloudWatch::Alarm",
279+
"Properties": {
280+
"Namespace": "AWS/Lambda",
281+
"MetricName": "Errors",
282+
"Threshold": 1,
283+
"Period": 60,
284+
"EvaluationPeriods": 1,
285+
"ComparisonOperator": "GreaterThanOrEqualToThreshold",
286+
"OKActions": [],
287+
"AlarmActions": [],
288+
"InsufficientDataActions": [],
289+
"Dimensions": [
290+
{
291+
"Name": "FunctionName",
292+
"Value": {
293+
"Ref": "HelloLambdaFunction"
294+
}
295+
}
296+
],
297+
"TreatMissingData": "missing",
298+
"Statistic": "Minimum"
299+
}
300+
}
301+
},
302+
"Outputs": {
303+
"ServerlessDeploymentBucketName": {
304+
"Value": {
305+
"Ref": "ServerlessDeploymentBucket"
306+
}
307+
},
308+
"HelloLambdaFunctionQualifiedArn": {
309+
"Description": "Current Lambda function version",
310+
"Value": {
311+
"Ref": "HelloLambdaVersionFYAirphUvjV7H12yGxU1eQrqAiSBMjAi9hdLPgV62L8"
312+
}
313+
},
314+
"PreHookLambdaFunctionQualifiedArn": {
315+
"Description": "Current Lambda function version",
316+
"Value": {
317+
"Ref": "PreHookLambdaVersionIYyrXlfQM5jjU68REvnAzRxhgq9eoLqSsDjy0"
318+
}
319+
},
320+
"PostHookLambdaFunctionQualifiedArn": {
321+
"Description": "Current Lambda function version",
322+
"Value": {
323+
"Ref": "PostHookLambdaVersiondh0VUUAh9BrmvORqx3vDEIcHxolKWKCO1YL45mVTbg"
324+
}
325+
}
326+
}
327+
}

0 commit comments

Comments
 (0)