File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed
samtranslator/model/eventsources Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,7 @@ class CloudWatchEvent(PushEventSource):
150
150
"Pattern" : PropertyType (False , is_type (dict )),
151
151
"Input" : PropertyType (False , is_str ()),
152
152
"InputPath" : PropertyType (False , is_str ()),
153
+ "Target" : PropertyType (False , is_type (dict )),
153
154
}
154
155
155
156
def to_cloudformation (self , ** kwargs ):
@@ -187,7 +188,8 @@ def _construct_target(self, function):
187
188
:returns: the Target property
188
189
:rtype: dict
189
190
"""
190
- target = {"Arn" : function .get_runtime_attr ("arn" ), "Id" : self .logical_id + "LambdaTarget" }
191
+ target_id = self .Target ["Id" ] if self .Target and "Id" in self .Target else self .logical_id + "LambdaTarget"
192
+ target = {"Arn" : function .get_runtime_attr ("arn" ), "Id" : target_id }
191
193
if self .Input is not None :
192
194
target ["Input" ] = self .Input
193
195
Original file line number Diff line number Diff line change
1
+ from mock import Mock , patch
2
+ from unittest import TestCase
3
+
4
+ from samtranslator .model .eventsources .push import CloudWatchEvent
5
+ from samtranslator .model .lambda_ import LambdaFunction
6
+
7
+
8
+ class CloudWatchEventSourceTests (TestCase ):
9
+ def setUp (self ):
10
+ self .logical_id = "EventLogicalId"
11
+ self .func = LambdaFunction ("func" )
12
+
13
+ def test_target_id_when_not_provided (self ):
14
+ cloudwatch_event_source = CloudWatchEvent (self .logical_id )
15
+ cfn = cloudwatch_event_source .to_cloudformation (function = self .func )
16
+ target_id = cfn [0 ].Targets [0 ]["Id" ]
17
+ self .assertEqual (target_id , "{}{}" .format (self .logical_id , "LambdaTarget" ))
18
+
19
+ def test_target_id_when_provided (self ):
20
+ cloudwatch_event_source = CloudWatchEvent (self .logical_id )
21
+ cloudwatch_event_source .Target = {"Id" : "MyTargetId" }
22
+ cfn = cloudwatch_event_source .to_cloudformation (function = self .func )
23
+ target_id = cfn [0 ].Targets [0 ]["Id" ]
24
+ self .assertEqual (target_id , "MyTargetId" )
You can’t perform that action at this time.
0 commit comments