Issue
I am trying to write a Cloudformation template which creates an EventBridge rule.
The EventBridge rule is supposed to stop an instance based on a schedule.
EventBridge target is expected as arn
parameter in Cloudformation template. I couldn't figure out the arn
value of the rule.
This is the template snippet I use:
{
"AWSTemplateFormatVersion": "2010-09-09"
"Resources": {
...
"Ec2StartStopRule": {
"Type": "AWS::Events::Rule",
"Properties": {
"Name": "ec2-stop-start-rule",
"RoleArn": {
"Fn::GetAtt": [
"Ec2StopStartRoleForEventBridge",
"Arn"
]
},
"ScheduleExpression": "cron(0 12 * * ? *)",
"Targets": [
{
"Arn": "ec2:StopInstances",
"Id": "Id1234",
"RunCommandParameters": {
"RunCommandTargets": [
{
"Key": "InstanceIds",
"Values": [
"mydata"
]
}
]
},
"RetryPolicy": {
"MaximumRetryAttempts": 2,
"MaximumEventAgeInSeconds": 3600
}
}
]
}
}
}
}
I receive following error:
Parameter ec2:StopInstances is not valid. Reason: Provided Arn is not in correct format.
I am sure EventBridge supports EC2 StopInstances API call as target: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html
But I cannot configure it using Cloudformation.
How to set 'EC2 StopInstances' API call as EventBridge target using Cloudformation?
Solution
This is not possible. Please see this link:
I would recommend to run a lambda as target and run the api call through it.
Answered By - Erik Asplund Answer Checked By - Marilyn (WPSolving Volunteer)