Skip to content

Commit a040f3c

Browse files
author
Connor Robertson
authored
feat: Input transformer for AWS::Serverless::Function.EventBridgeRule (#3283)
1 parent cb20917 commit a040f3c

File tree

8 files changed

+627
-0
lines changed

8 files changed

+627
-0
lines changed

samtranslator/internal/schema_source/aws_serverless_function.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ class EventBridgeRuleEventProperties(BaseModel):
333333
Pattern: PassThroughProp = eventbridgeruleeventproperties("Pattern")
334334
RetryPolicy: Optional[PassThroughProp] = eventbridgeruleeventproperties("RetryPolicy")
335335
Target: Optional[EventBridgeRuleTarget] = eventbridgeruleeventproperties("Target")
336+
InputTransformer: Optional[PassThroughProp] # TODO: add docs
336337

337338

338339
class EventBridgeRuleEvent(BaseModel):

samtranslator/model/eventsources/push.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ class CloudWatchEvent(PushEventSource):
207207
"Target": PropertyType(False, IS_DICT),
208208
"Enabled": PropertyType(False, IS_BOOL),
209209
"State": PropertyType(False, IS_STR),
210+
"InputTransformer": PropertyType(False, IS_DICT),
210211
}
211212

212213
EventBusName: Optional[PassThrough]
@@ -219,6 +220,7 @@ class CloudWatchEvent(PushEventSource):
219220
Target: Optional[PassThrough]
220221
Enabled: Optional[bool]
221222
State: Optional[PassThrough]
223+
InputTransformer: Optional[PassThrough]
222224

223225
@cw_timer(prefix=FUNCTION_EVETSOURCE_METRIC_PREFIX)
224226
def to_cloudformation(self, **kwargs): # type: ignore[no-untyped-def]
@@ -291,6 +293,9 @@ def _construct_target(self, function, dead_letter_queue_arn=None): # type: igno
291293
if self.RetryPolicy is not None:
292294
target["RetryPolicy"] = self.RetryPolicy
293295

296+
if self.InputTransformer is not None:
297+
target["InputTransformer"] = self.InputTransformer
298+
294299
return target
295300

296301

samtranslator/schema/schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246854,6 +246854,9 @@
246854246854
"markdownDescription": "When you don't want to pass the entire matched event to the target, use the `InputPath` property to describe which part of the event to pass\\. \n*Type*: String \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`InputPath`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-inputpath) property of an `AWS::Events::Rule Target` resource\\.",
246855246855
"title": "InputPath"
246856246856
},
246857+
"InputTransformer": {
246858+
"$ref": "#/definitions/PassThroughProp"
246859+
},
246857246860
"Pattern": {
246858246861
"allOf": [
246859246862
{

schema_source/sam.schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5086,6 +5086,9 @@
50865086
"markdownDescription": "When you don't want to pass the entire matched event to the target, use the `InputPath` property to describe which part of the event to pass\\. \n*Type*: String \n*Required*: No \n*AWS CloudFormation compatibility*: This property is passed directly to the [`InputPath`](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-events-rule-target.html#cfn-events-rule-target-inputpath) property of an `AWS::Events::Rule Target` resource\\.",
50875087
"title": "InputPath"
50885088
},
5089+
"InputTransformer": {
5090+
"$ref": "#/definitions/PassThroughProp"
5091+
},
50895092
"Pattern": {
50905093
"allOf": [
50915094
{
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Resources:
2+
ScheduledFunction:
3+
Type: AWS::Serverless::Function
4+
Properties:
5+
CodeUri: s3://sam-demo-bucket/hello.zip?versionId=3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO
6+
Handler: hello.handler
7+
Runtime: python2.7
8+
Events:
9+
Schedule:
10+
Type: Schedule
11+
Properties:
12+
Schedule: rate(1 minute)
13+
TriggeredFunction:
14+
Type: AWS::Serverless::Function
15+
Properties:
16+
CodeUri: s3://sam-demo-bucket/hello.zip?versionId=3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO
17+
Handler: hello.handler
18+
Runtime: python2.7
19+
Events:
20+
OnTerminate:
21+
Type: EventBridgeRule
22+
Properties:
23+
EventBusName: ExternalEventBridge
24+
Pattern:
25+
detail:
26+
state:
27+
- terminated
28+
Target:
29+
Id: hello345
30+
InputTransformer:
31+
InputPathsMap:
32+
instance: $.detail.instance-id
33+
state: $.detail.state
34+
InputTemplate: |
35+
{
36+
"instance" : <instance>,
37+
"state" : <state>,
38+
"instanceStatus": "instance \"<instance>\" is in <state>"
39+
}
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
{
2+
"Resources": {
3+
"ScheduledFunction": {
4+
"Properties": {
5+
"Code": {
6+
"S3Bucket": "sam-demo-bucket",
7+
"S3Key": "hello.zip",
8+
"S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO"
9+
},
10+
"Handler": "hello.handler",
11+
"Role": {
12+
"Fn::GetAtt": [
13+
"ScheduledFunctionRole",
14+
"Arn"
15+
]
16+
},
17+
"Runtime": "python2.7",
18+
"Tags": [
19+
{
20+
"Key": "lambda:createdBy",
21+
"Value": "SAM"
22+
}
23+
]
24+
},
25+
"Type": "AWS::Lambda::Function"
26+
},
27+
"ScheduledFunctionRole": {
28+
"Properties": {
29+
"AssumeRolePolicyDocument": {
30+
"Statement": [
31+
{
32+
"Action": [
33+
"sts:AssumeRole"
34+
],
35+
"Effect": "Allow",
36+
"Principal": {
37+
"Service": [
38+
"lambda.amazonaws.com"
39+
]
40+
}
41+
}
42+
],
43+
"Version": "2012-10-17"
44+
},
45+
"ManagedPolicyArns": [
46+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
47+
],
48+
"Tags": [
49+
{
50+
"Key": "lambda:createdBy",
51+
"Value": "SAM"
52+
}
53+
]
54+
},
55+
"Type": "AWS::IAM::Role"
56+
},
57+
"ScheduledFunctionSchedule": {
58+
"Properties": {
59+
"ScheduleExpression": "rate(1 minute)",
60+
"Targets": [
61+
{
62+
"Arn": {
63+
"Fn::GetAtt": [
64+
"ScheduledFunction",
65+
"Arn"
66+
]
67+
},
68+
"Id": "ScheduledFunctionScheduleLambdaTarget"
69+
}
70+
]
71+
},
72+
"Type": "AWS::Events::Rule"
73+
},
74+
"ScheduledFunctionSchedulePermission": {
75+
"Properties": {
76+
"Action": "lambda:InvokeFunction",
77+
"FunctionName": {
78+
"Ref": "ScheduledFunction"
79+
},
80+
"Principal": "events.amazonaws.com",
81+
"SourceArn": {
82+
"Fn::GetAtt": [
83+
"ScheduledFunctionSchedule",
84+
"Arn"
85+
]
86+
}
87+
},
88+
"Type": "AWS::Lambda::Permission"
89+
},
90+
"TriggeredFunction": {
91+
"Properties": {
92+
"Code": {
93+
"S3Bucket": "sam-demo-bucket",
94+
"S3Key": "hello.zip",
95+
"S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO"
96+
},
97+
"Handler": "hello.handler",
98+
"Role": {
99+
"Fn::GetAtt": [
100+
"TriggeredFunctionRole",
101+
"Arn"
102+
]
103+
},
104+
"Runtime": "python2.7",
105+
"Tags": [
106+
{
107+
"Key": "lambda:createdBy",
108+
"Value": "SAM"
109+
}
110+
]
111+
},
112+
"Type": "AWS::Lambda::Function"
113+
},
114+
"TriggeredFunctionOnTerminate": {
115+
"Properties": {
116+
"EventBusName": "ExternalEventBridge",
117+
"EventPattern": {
118+
"detail": {
119+
"state": [
120+
"terminated"
121+
]
122+
}
123+
},
124+
"Targets": [
125+
{
126+
"Arn": {
127+
"Fn::GetAtt": [
128+
"TriggeredFunction",
129+
"Arn"
130+
]
131+
},
132+
"Id": "hello345",
133+
"InputTransformer": {
134+
"InputPathsMap": {
135+
"instance": "$.detail.instance-id",
136+
"state": "$.detail.state"
137+
},
138+
"InputTemplate": "{\n\"instance\" : <instance>,\n\"state\" : <state>,\n\"instanceStatus\": \"instance \\\"<instance>\\\" is in <state>\"\n}\n"
139+
}
140+
}
141+
]
142+
},
143+
"Type": "AWS::Events::Rule"
144+
},
145+
"TriggeredFunctionOnTerminatePermission": {
146+
"Properties": {
147+
"Action": "lambda:InvokeFunction",
148+
"FunctionName": {
149+
"Ref": "TriggeredFunction"
150+
},
151+
"Principal": "events.amazonaws.com",
152+
"SourceArn": {
153+
"Fn::GetAtt": [
154+
"TriggeredFunctionOnTerminate",
155+
"Arn"
156+
]
157+
}
158+
},
159+
"Type": "AWS::Lambda::Permission"
160+
},
161+
"TriggeredFunctionRole": {
162+
"Properties": {
163+
"AssumeRolePolicyDocument": {
164+
"Statement": [
165+
{
166+
"Action": [
167+
"sts:AssumeRole"
168+
],
169+
"Effect": "Allow",
170+
"Principal": {
171+
"Service": [
172+
"lambda.amazonaws.com"
173+
]
174+
}
175+
}
176+
],
177+
"Version": "2012-10-17"
178+
},
179+
"ManagedPolicyArns": [
180+
"arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
181+
],
182+
"Tags": [
183+
{
184+
"Key": "lambda:createdBy",
185+
"Value": "SAM"
186+
}
187+
]
188+
},
189+
"Type": "AWS::IAM::Role"
190+
}
191+
}
192+
}

0 commit comments

Comments
 (0)