为什么我的 CloudWatch Canary 会停止运行?

上次更新时间:2020 年 10 月 13 日

我使用 AWS CloudFormation 或 AWS 命令行界面 (AWS CLI) 在 Amazon CloudWatch 中创建了一个 Canary。Canary 在一段时间后自动停止运行。该如何排查此问题?

解决方法

注意:如果在运行 AWS CLI 命令时收到错误,请确保您使用的是最新版本的 AWS CLI

如果 CloudWatch Canary 停止运行,请检查您在创建 Canary 时设置的“DurationInSeconds”值。该值指定 Canary 根据“Expression”值中的计划持续进行常规运行的时长(以秒为单位)。如果指定 0,Canary 将一直运行到您将其停止为止。如果省略此字段,则使用默认值 0。

要查看 Canary 的“DurationInSeconds”参数值,请运行 Amazon CloudWatch Synthetics GetCanary API:

aws synthetics  get-canary --name [canary_name]

在输出中查看“DurationInSeconds”的值:

{
    "Canary": {
        "Id": "a1495b85-1c60-4f29-92c1-540f62fa34e3",
        "Name": "canary_name",
        "Code": {
            "SourceLocationArn": "arn:aws:lambda:eu-west-1:YourAccount:layer:cwsyn-canary_name-a1495b85-1c60-4f29-92c1-540f62fa34e3:1",
            "Handler": "CanaryFunction.handler"
        },
        "ExecutionRoleArn": "arn:aws:iam::YourAccount:role/CanaryRoleName",
        "Schedule": {
            "Expression": "rate(2 minutes)",
            "DurationInSeconds": 360
        },
        "RunConfig": {
            "TimeoutInSeconds": 120
        },
        "SuccessRetentionPeriodInDays": 31,
        "FailureRetentionPeriodInDays": 31,
        "Status": {
            "State": "READY"
        },
        "Timeline": {
            "Created": 1594481063.96,
            "LastModified": 1594481063.96
        },
        "ArtifactS3Location": "S3_Bucket_for_artifacts",
        "EngineArn": "arn:aws:lambda:eu-west-1:YourAccount:function:cwsyn-canary_name-a1495b85-1c60-4f29-92c1-540f62fa34e3:1",
        "RuntimeVersion": "syn-1.0",
        "Tags": {}
    }
}

注意:在该响应中,“DurationInSeconds”不等于 0。

如果“DurationInSeconds”值与您期望的持续时间不符,请运行 CloudWatch Synthetics UpdateCanary API:

aws synthetics  update-canary --name canary_cli --schedule Expression="rate(2 minutes)",DurationInSeconds=0

注意:要使 Canary 持续运行,您必须编写“DurationInSeconds”设置为 0 的计划表达式。

要验证您的更改,请使用 AWS CLI 运行 CloudWatch Synthetics get-canary 命令:

aws synthetics  get-canary --name [canary_name]
{
    "Canary": {
        "Id": "a1495b85-1c60-4f29-92c1-540f62fa34e3",
        "Name": "canary_name",
        "Code": {
            "SourceLocationArn": "arn:aws:lambda:eu-west-1:YourAccount:layer:cwsyn-canary_name-a1495b85-1c60-4f29-92c1-540f62fa34e3:1",
            "Handler": "CanaryFunction.handler"
        },
        "ExecutionRoleArn": "arn:aws:iam::YourAccount:role/CanaryRoleName",
        "Schedule": {
            "Expression": "rate(2 minutes)",
            "DurationInSeconds": 0
        },
        "RunConfig": {
            "TimeoutInSeconds": 120
        },
        "SuccessRetentionPeriodInDays": 31,
        "FailureRetentionPeriodInDays": 31,
        "Status": {
            "State": "READY"
        },
        "Timeline": {
            "Created": 1594481063.96,
            "LastModified": 1594481063.96
        },
        "ArtifactS3Location": "S3_Bucket_for_artifacts",
        "EngineArn": "arn:aws:lambda:eu-west-1:YourAccount:function:cwsyn-canary_name-a1495b85-1c60-4f29-92c1-540f62fa34e3:1",
        "RuntimeVersion": "syn-1.0",
        "Tags": {}
    }
}

在输出中确认“DurationInSeconds”的值为 0。</p


这篇文章对您有帮助吗?


您是否需要账单或技术支持?