2 Answers
- Newest
- Most votes
- Most comments
0
Hello ,
From the above problem statement I understand you were facing synatx issue while specifying the property InputTemplate in cloudformation.
The correct syntax would be :
input_template=f'{{"InstanceId": [<instanceid>],"ASGName": [<asgname>],"LCHName": [<lchname>],"automationAssumeRole": ["{cw_event_role.role_arn}"]}}'
Also I would like to provide the full code I tested:
input_transformer_property = events.CfnRule.InputTransformerProperty(
input_paths_map={
"asgname": "$.detail.AutoScalingGroupName",
"instanceid": "$.detail.EC2InstanceId",
"lchname": "$.detail.LifecycleHookName"
},
input_template=f'{{"InstanceId": [<instanceid>],"ASGName": [<asgname>],"LCHName": [<lchname>],"automationAssumeRole": ["{cw_event_role.role_arn}"]}}'
)
Below is synthesized cfn template from cdk synth command:
JSON :
"MyCfnRule": {
"Type": "AWS::Events::Rule",
"Properties": {
"Description": "My event rule",
"ScheduleExpression": "cron(0 0 * * ? *)",
"State": "ENABLED",
"Targets": [
{
"Arn": {
"Fn::GetAtt": [
"HelloHandler2E4FBA4D",
"Arn"
]
},
"Id": "MyTarget",
"InputTransformer": {
"InputPathsMap": {
"asgname": "$.detail.AutoScalingGroupName",
"instanceid": "$.detail.EC2InstanceId",
"lchname": "$.detail.LifecycleHookName"
},
"InputTemplate": {
"Fn::Join": [
"",
[
"{\"InstanceId\": [<instanceid>],\"ASGName\": [<asgname>],\"LCHName\": [<lchname>],\"automationAssumeRole\": [\"",
{
"Fn::GetAtt": [
"cweventroleid23238EBB2881",
"Arn"
]
},
"\"]}"
]
]
}
}
}
]
}
Yaml :
MyCfnRule:
Type: 'AWS::Events::Rule'
Properties:
Description: My event rule
ScheduleExpression: cron(0 0 * * ? *)
State: ENABLED
Targets:
- Arn: !GetAtt
- HelloHandler2E4FBA4D
- Arn
Id: MyTarget
InputTransformer:
InputPathsMap:
asgname: $.detail.AutoScalingGroupName
instanceid: $.detail.EC2InstanceId
lchname: $.detail.LifecycleHookName
InputTemplate: !Join
- ''
- - >-
{"InstanceId": [<instanceid>],"ASGName":
[<asgname>],"LCHName": [<lchname>],"automationAssumeRole": ["
- !GetAtt
- cweventroleid23238EBB2881
- Arn
- '"]}'
answered 8 months ago
0
Holy molly, thank you! Couldn't figure it out that I need to add 2nd {} pair
answered 8 months ago
Relevant content
- asked 2 years ago
- asked 4 months ago
- asked 5 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated a year ago