繁体   English   中英

如何使用 Cloudformation 将“EC2 StopInstances”API 调用设置为 EventBridge 目标

[英]How to set 'EC2 StopInstances' API call as EventBridge target using Cloudformation

我正在尝试编写一个创建 EventBridge 规则的 Cloudformation 模板。

EventBridge 规则应该根据计划停止实例。

EventBridge 目标应作为 Cloudformation 模板中的arn参数。 我无法弄清楚规则的arn值。

这是我使用的模板片段:

 {
    "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
                        }
                    }
                ]
            }
        }
    }
}

我收到以下错误:

Parameter ec2:StopInstances is not valid. Reason: Provided Arn is not in correct format.

我确定 EventBridge 支持 EC2 StopInstances API 调用作为目标: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html

但我无法使用 Cloudformation 配置它。

如何使用 Cloudformation 将“EC2 StopInstances”API 调用设置为 EventBridge 目标?

这是不可能的。 请查看此链接:

有关目标支持的 AWS 文档

我建议运行 lambda 作为目标并通过它运行 api 调用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM