Skip to content

Commit f313094

Browse files
authored
Test CloudWatchEvent Properties With Intrinsic Functions (#2090)
* Add headers whenever cors is set * Add cw event success cases * Replace GetAtt with condition * Cleanup test yaml * Cleanup test yaml * Remove files * Add intrinsic to pattern field * Fix wrong files committed
1 parent 4e8c607 commit f313094

File tree

5 files changed

+473
-0
lines changed

5 files changed

+473
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Parameters:
2+
PathA:
3+
Type: String
4+
Default: "SomeInputPath"
5+
PathB:
6+
Type: String
7+
Default: "AnotherInputPath"
8+
9+
Conditions:
10+
PathCondition:
11+
Fn::Equals:
12+
- true
13+
- true
14+
15+
Resources:
16+
LambdaFunction:
17+
Type: 'AWS::Serverless::Function'
18+
Properties:
19+
CodeUri: s3://sam-demo-bucket/hello.zip
20+
Handler: hello.handler
21+
Runtime: python2.7
22+
Events:
23+
OnTerminate:
24+
Type: CloudWatchEvent
25+
Properties:
26+
EventBusName: !Join [ "", [ "Event", "Bus", "Name" ] ]
27+
Input: !Join [ ":", [ "{ Key", "Value }" ] ]
28+
InputPath: !If [ PathCondition, !Ref PathA, !Ref PathB ]
29+
Pattern:
30+
detail:
31+
state: !Split [ "," , "terminated,stopped" ]
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{
2+
"Parameters": {
3+
"PathA": {
4+
"Type": "String",
5+
"Default": "SomeInputPath"
6+
},
7+
"PathB": {
8+
"Type": "String",
9+
"Default": "AnotherInputPath"
10+
}
11+
},
12+
"Conditions": {
13+
"PathCondition": {
14+
"Fn::Equals": [
15+
true,
16+
true
17+
]
18+
}
19+
},
20+
"Resources": {
21+
"LambdaFunction": {
22+
"Type": "AWS::Lambda::Function",
23+
"Properties": {
24+
"Code": {
25+
"S3Bucket": "sam-demo-bucket",
26+
"S3Key": "hello.zip"
27+
},
28+
"Handler": "hello.handler",
29+
"Role": {
30+
"Fn::GetAtt": [
31+
"LambdaFunctionRole",
32+
"Arn"
33+
]
34+
},
35+
"Runtime": "python2.7",
36+
"Tags": [
37+
{
38+
"Key": "lambda:createdBy",
39+
"Value": "SAM"
40+
}
41+
]
42+
}
43+
},
44+
"LambdaFunctionRole": {
45+
"Type": "AWS::IAM::Role",
46+
"Properties": {
47+
"AssumeRolePolicyDocument": {
48+
"Version": "2012-10-17",
49+
"Statement": [
50+
{
51+
"Action": [
52+
"sts:AssumeRole"
53+
],
54+
"Effect": "Allow",
55+
"Principal": {
56+
"Service": [
57+
"lambda.amazonaws.com"
58+
]
59+
}
60+
}
61+
]
62+
},
63+
"ManagedPolicyArns": [
64+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
65+
],
66+
"Tags": [
67+
{
68+
"Key": "lambda:createdBy",
69+
"Value": "SAM"
70+
}
71+
]
72+
}
73+
},
74+
"LambdaFunctionOnTerminate": {
75+
"Type": "AWS::Events::Rule",
76+
"Properties": {
77+
"EventBusName": {
78+
"Fn::Join": [
79+
"",
80+
[
81+
"Event",
82+
"Bus",
83+
"Name"
84+
]
85+
]
86+
},
87+
"EventPattern": {
88+
"detail": {
89+
"state": {
90+
"Fn::Split": [
91+
",",
92+
"terminated,stopped"
93+
]
94+
}
95+
}
96+
},
97+
"Targets": [
98+
{
99+
"Arn": {
100+
"Fn::GetAtt": [
101+
"LambdaFunction",
102+
"Arn"
103+
]
104+
},
105+
"Id": "LambdaFunctionOnTerminateLambdaTarget",
106+
"Input": {
107+
"Fn::Join": [
108+
":",
109+
[
110+
"{ Key",
111+
"Value }"
112+
]
113+
]
114+
},
115+
"InputPath": {
116+
"Fn::If": [
117+
"PathCondition",
118+
{
119+
"Ref": "PathA"
120+
},
121+
{
122+
"Ref": "PathB"
123+
}
124+
]
125+
}
126+
}
127+
]
128+
}
129+
},
130+
"LambdaFunctionOnTerminatePermission": {
131+
"Type": "AWS::Lambda::Permission",
132+
"Properties": {
133+
"Action": "lambda:InvokeFunction",
134+
"FunctionName": {
135+
"Ref": "LambdaFunction"
136+
},
137+
"Principal": "events.amazonaws.com",
138+
"SourceArn": {
139+
"Fn::GetAtt": [
140+
"LambdaFunctionOnTerminate",
141+
"Arn"
142+
]
143+
}
144+
}
145+
}
146+
}
147+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
{
2+
"Parameters": {
3+
"PathA": {
4+
"Type": "String",
5+
"Default": "SomeInputPath"
6+
},
7+
"PathB": {
8+
"Type": "String",
9+
"Default": "AnotherInputPath"
10+
}
11+
},
12+
"Conditions": {
13+
"PathCondition": {
14+
"Fn::Equals": [
15+
true,
16+
true
17+
]
18+
}
19+
},
20+
"Resources": {
21+
"LambdaFunction": {
22+
"Type": "AWS::Lambda::Function",
23+
"Properties": {
24+
"Code": {
25+
"S3Bucket": "sam-demo-bucket",
26+
"S3Key": "hello.zip"
27+
},
28+
"Handler": "hello.handler",
29+
"Role": {
30+
"Fn::GetAtt": [
31+
"LambdaFunctionRole",
32+
"Arn"
33+
]
34+
},
35+
"Runtime": "python2.7",
36+
"Tags": [
37+
{
38+
"Key": "lambda:createdBy",
39+
"Value": "SAM"
40+
}
41+
]
42+
}
43+
},
44+
"LambdaFunctionRole": {
45+
"Type": "AWS::IAM::Role",
46+
"Properties": {
47+
"AssumeRolePolicyDocument": {
48+
"Version": "2012-10-17",
49+
"Statement": [
50+
{
51+
"Action": [
52+
"sts:AssumeRole"
53+
],
54+
"Effect": "Allow",
55+
"Principal": {
56+
"Service": [
57+
"lambda.amazonaws.com"
58+
]
59+
}
60+
}
61+
]
62+
},
63+
"ManagedPolicyArns": [
64+
"arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
65+
],
66+
"Tags": [
67+
{
68+
"Key": "lambda:createdBy",
69+
"Value": "SAM"
70+
}
71+
]
72+
}
73+
},
74+
"LambdaFunctionOnTerminate": {
75+
"Type": "AWS::Events::Rule",
76+
"Properties": {
77+
"EventBusName": {
78+
"Fn::Join": [
79+
"",
80+
[
81+
"Event",
82+
"Bus",
83+
"Name"
84+
]
85+
]
86+
},
87+
"EventPattern": {
88+
"detail": {
89+
"state": {
90+
"Fn::Split": [
91+
",",
92+
"terminated,stopped"
93+
]
94+
}
95+
}
96+
},
97+
"Targets": [
98+
{
99+
"Arn": {
100+
"Fn::GetAtt": [
101+
"LambdaFunction",
102+
"Arn"
103+
]
104+
},
105+
"Id": "LambdaFunctionOnTerminateLambdaTarget",
106+
"Input": {
107+
"Fn::Join": [
108+
":",
109+
[
110+
"{ Key",
111+
"Value }"
112+
]
113+
]
114+
},
115+
"InputPath": {
116+
"Fn::If": [
117+
"PathCondition",
118+
{
119+
"Ref": "PathA"
120+
},
121+
{
122+
"Ref": "PathB"
123+
}
124+
]
125+
}
126+
}
127+
]
128+
}
129+
},
130+
"LambdaFunctionOnTerminatePermission": {
131+
"Type": "AWS::Lambda::Permission",
132+
"Properties": {
133+
"Action": "lambda:InvokeFunction",
134+
"FunctionName": {
135+
"Ref": "LambdaFunction"
136+
},
137+
"Principal": "events.amazonaws.com",
138+
"SourceArn": {
139+
"Fn::GetAtt": [
140+
"LambdaFunctionOnTerminate",
141+
"Arn"
142+
]
143+
}
144+
}
145+
}
146+
}
147+
}

0 commit comments

Comments
 (0)