AWS boto3 CloudWatch Events put_rule - 参数 EventPattern 的类型无效

Nov*_*eMe 0 amazon-web-services boto3

我正在尝试运行以下代码:

response = events.put_rule(
    Name = "DEMO_EVENT",
    EventPattern = ({
        "source": [
            "aws.ec2"
        ],
        "detail-type": [
            "Notification"
        ],
        "detail": {
            "state": [
            "running",
            "shutting-down"
            ],
            "instance-id": [
            "i-***",
            "i-***"
            ]
        }
    }),
    State="ENABLED"
)
Run Code Online (Sandbox Code Playgroud)

继续收到以下错误: type: ,有效类型:

我尝试改变很多东西但仍然无法运行它。有人可以告诉我错误是什么吗?

Nov*_*eMe 5

我想到了。这可能会在将来帮助其他人:

response = events.put_rule(
    Name = "DEMO_EVENT",
    EventPattern = """
        {
        "source": [
            "aws.ec2"
        ],
        "detail-type": [
            "Notification"
        ],
        "detail": {
            "state": [
            "running",
            "shutting-down"
            ],
            "instance-id": [
            "i-***",
            "i-***"
            ]
        }
    }
    """,
    State="ENABLED"
)
Run Code Online (Sandbox Code Playgroud)