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 CLI commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.
Run the following get-canary command to check the DurationInSeconds value that you set when you created your canary:
aws synthetics get-canary --name CANARY_NAME
Note: Replace CANARY_NAME with your canary's name. The DurationInSeconds parameter specifies how long the canary continues running on the schedule you defined in the Expression parameter. If you specify 0, then the canary continues to run until you stop the canary. If you don't specify a value, then the default is 0.
Then, in the output, find the DurationInSeconds value in the Schedule section.
Example output:
{
"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": {}
}
}
In the preceding output, DurationInSeconds isn't equal to 0.
If the DurationInSeconds value doesn't match your intended duration, then run the following update-canary command to change it:
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 confirm your changes, run the get-canary command again:
aws synthetics get-canary --name CANARY_NAME
Example output:
{
"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.