I created a canary in Amazon CloudWatch with AWS CloudFormation or the AWS Command Line Interface (AWS CLI). I want to know why the canary automatically stops running after a period of time.
Resolution
Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshoot AWS CLI errors. Also, make sure that you use the most recent AWS CLI version.
If your CloudWatch canary stops running, then check the DurationInSeconds value that you set when you created your canary. This value specifies the length of time that the canary continues to make regular runs according to the schedule in the Expression value. The length of time is in seconds. If you specify 0, then the canary continues to run until you stop the canary. If you don't set the DurationInSeconds value, then the default value is set to 0.
To check your canary's DurationInSeconds parameter value, run the CloudWatch Synthetics GetCanary API:
aws synthetics get-canary --name [canary_name]
In the following output, check the DurationInSeconds value:
{
"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": {}
}
}
Note: In the preceding output, DurationInSeconds isn't equal to 0.
If the DurationInSeconds value doesn't match your intended duration, then run the following CloudWatch Synthetics UpdateCanary API:
aws synthetics update-canary --name canary_cli --schedule Expression="rate(2 minutes)",DurationInSeconds=0
Note: For the canary to continuously run, you must write the schedule Expression with DurationInSeconds set to 0.
To verify your changes, use the AWS CLI to run the get-canary command:
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": {}
}
}
In the output, confirm that the DurationInSeconds value is 0.