Home / AWS

AWSRunbookIntermediate

CloudWatch Synthetics canary failing or stuck in ERROR: execution role, artifact bucket, VPC egress and deprecated runtimes

A canary alarm fired but the site looks fine, or the canary won't start at all. Read the run reason, then check the role, artifact bucket, VPC path, timeout and runtime.

Deepak Bhardwaj8 min read

Applies toAmazon CloudWatch Synthetics (Node.js Puppeteer, Node.js Playwright and Python Selenium runtimes), AWS CLI v2

Symptom

One of these usually lands on the on-call engineer:

  • A SuccessPercent alarm fires on a canary, but the page or API it checks works fine in a browser.
  • A new or edited canary sits in ERROR or STOPPED and never runs.
  • Runs show FAILED with no screenshots or HAR files in S3.
  • A canary that worked for months starts failing after a runtime deprecation notice or a network change.

Before you can tell a real outage from a broken canary, you need the run's state reason. This runbook starts there.

Step 1: read the canary and its last runs

Get the canary's state and the settings that cause most failures:

CANARY=checkout-api

aws synthetics get-canary --name "$CANARY" \
  --query 'Canary.{State:Status.State,Reason:Status.StateReason,Runtime:RuntimeVersion,Role:ExecutionRoleArn,Artifacts:ArtifactS3Location,Timeout:RunConfig.TimeoutInSeconds,Schedule:Schedule.Expression,Vpc:VpcConfig.SubnetIds}'

Then list the most recent runs and their reasons:

aws synthetics get-canary-runs --name "$CANARY" --max-results 10 \
  --query 'CanaryRuns[].{Start:Timeline.Started,State:Status.State,Code:Status.StateReasonCode,Reason:Status.StateReason}' \
  --output table

For a quick view across every canary in the Region:

aws synthetics describe-canaries-last-run \
  --query 'CanariesLastRun[].{Name:CanaryName,State:LastRun.Status.State,Reason:LastRun.Status.StateReason}' \
  --output table

A run's State is RUNNING, PASSED or FAILED. The StateReasonCode tells you which kind of failure it was:

StateReasonCode What it means Where to look
CANARY_FAILURE The script failed (assertion, timeout, navigation error) or Synthetics hit a fatal error running it Run reason text, canary logs, screenshots
EXECUTION_FAILURE Something outside the check failed, for example saving screenshots or HAR files Execution role, artifact bucket, VPC path to S3

If both happen in one run, CANARY_FAILURE is reported. The StateReason text holds the actual error, so read it before you change anything.

Step 2: map the reason to a cause

Reason text or symptom Likely cause Fix
Canary state ERROR right after create or update Execution role missing or not trusted by Lambda, bad handler, or a script package that failed to upload Check Status.StateReason on the canary, fix the role or handler, then update-canary
Access Denied uploading artifacts, or no files in S3 Role lacks s3:PutObject on the artifact prefix, or a bucket policy or KMS key denies it Step 3
Navigation timeout, net::ERR_NAME_NOT_RESOLVED or ETIMEDOUT for a public URL Canary runs in a VPC with no NAT path, or a private DNS name is not resolvable from that VPC Step 4
Runs time out with no clear script error RunConfig.TimeoutInSeconds shorter than the script needs, or a page waiting on a slow third-party asset Step 5
Failures started after an AWS notice, and runs report a runtime error Runtime version deprecated Step 6
Waiting for selector ... failed The page changed. The site works; the script is stale Update the selector in the script
403 from the target WAF or bot protection blocking the canary's source IPs or user agent Add a narrow WAF exception for the canary

Tip

Open the screenshot from the failed run before anything else. A screenshot of a login page, a cookie banner or a WAF block page answers most "the site is fine but the canary fails" cases in a few seconds.

Step 3: check the execution role and artifact bucket

Find the role and list what it has attached:

ROLE_ARN=$(aws synthetics get-canary --name "$CANARY" --query 'Canary.ExecutionRoleArn' --output text)
ROLE=${ROLE_ARN##*/}

aws iam list-attached-role-policies --role-name "$ROLE"
aws iam list-role-policies --role-name "$ROLE"
aws iam get-role --role-name "$ROLE" --query 'Role.AssumeRolePolicyDocument'

The trust policy must allow lambda.amazonaws.com. The permissions policy needs at least:

  • s3:PutObject on the artifact bucket and prefix, plus s3:GetBucketLocation on the bucket and s3:ListAllMyBuckets.
  • cloudwatch:PutMetricData, usually limited with a condition on cloudwatch:namespace = CloudWatchSynthetics.
  • logs:CreateLogGroup, logs:CreateLogStream and logs:PutLogEvents.
  • For VPC canaries: ec2:CreateNetworkInterface, ec2:DescribeNetworkInterfaces and ec2:DeleteNetworkInterface.

Test the S3 write from the role's point of view with the policy simulator:

aws iam simulate-principal-policy \
  --policy-source-arn "$ROLE_ARN" \
  --action-names s3:PutObject \
  --resource-arns "arn:aws:s3:::my-canary-artifacts/canary/us-east-1/$CANARY/test.png" \
  --query 'EvaluationResults[].{Action:EvalActionName,Decision:EvalDecision}'

The simulator does not evaluate bucket policies on its own. If it returns allowed but uploads still fail, check the bucket:

aws s3api get-bucket-policy --bucket my-canary-artifacts --query Policy --output text
aws s3api get-bucket-encryption --bucket my-canary-artifacts

If the bucket uses SSE-KMS with a customer managed key, the role also needs kms:GenerateDataKey on that key, and the key policy must allow it.

Step 4: check the network path for VPC canaries

A canary attached to a VPC runs in your private subnets. It needs a route to the target and to the AWS services it writes to: S3 for artifacts, CloudWatch for metrics and CloudWatch Logs.

aws synthetics get-canary --name "$CANARY" --query 'Canary.VpcConfig'

# Default route of each subnet's route table
for SUBNET in subnet-0aaa subnet-0bbb; do
  aws ec2 describe-route-tables \
    --filters Name=association.subnet-id,Values=$SUBNET \
    --query 'RouteTables[].Routes[?DestinationCidrBlock==`0.0.0.0/0`].[NatGatewayId,GatewayId,TransitGatewayId]' \
    --output text
done

# Endpoints present in the VPC
aws ec2 describe-vpc-endpoints --filters Name=vpc-id,Values=vpc-0123 \
  --query 'VpcEndpoints[].{Service:ServiceName,Type:VpcEndpointType,State:State}' --output table
What you find Result Fix
No 0.0.0.0/0 route and no endpoints Public URLs time out and artifact uploads fail Add a NAT gateway route, or add an S3 gateway endpoint plus monitoring and logs interface endpoints
Route goes to an internet gateway Lambda ENIs get no public IP, so traffic fails Use private subnets with a NAT route
Interface endpoints exist but calls hang Endpoint security group blocks 443 from the canary's security group Allow inbound 443 from the canary security group
Target is a private hostname The VPC can't resolve it Associate the private hosted zone with the VPC, or add a Resolver rule

If an endpoint policy restricts S3 to specific buckets, the artifact bucket must be on that list.

Step 5: rule out timeouts and flaky pages

Compare how long runs take with the configured timeout:

aws cloudwatch get-metric-statistics \
  --namespace CloudWatchSynthetics --metric-name Duration \
  --dimensions Name=CanaryName,Value="$CANARY" \
  --start-time "$(date -u -d '-6 hours' +%FT%TZ)" --end-time "$(date -u +%FT%TZ)" \
  --period 300 --statistics Average Maximum

Duration is in milliseconds. If the maximum is close to RunConfig.TimeoutInSeconds, raise the timeout or remove the slow step. The timeout must also be shorter than the schedule interval, or runs overlap and get skipped:

aws synthetics update-canary --name "$CANARY" --run-config TimeoutInSeconds=120

Read the canary's own logs in CloudWatch Logs. The canary runs as a Lambda function whose name starts with cwsyn-<canary-name>. Log group names vary by runtime and setup, so find them by prefix:

aws logs describe-log-groups --log-group-name-prefix "/aws/lambda/cwsyn-$CANARY" \
  --query 'logGroups[].logGroupName'

Step 6: move off a deprecated runtime

List the runtimes and their deprecation dates:

aws synthetics describe-runtime-versions \
  --query 'RuntimeVersions[].{Version:VersionName,Released:ReleaseDate,Deprecated:DeprecationDate}' \
  --output table

Find canaries on runtimes that are deprecated or about to be:

aws synthetics describe-canaries \
  --query 'Canaries[].{Name:Name,Runtime:RuntimeVersion,State:Status.State}' --output table

Update one canary at a time and watch the next few runs. Runtime names follow patterns such as syn-nodejs-puppeteer-<n>.<n>, syn-nodejs-playwright-<n>.<n> and syn-python-selenium-<n>.<n>. Take the current value from the output above rather than copying a version number from an old example:

aws synthetics update-canary --name "$CANARY" --runtime-version <current-runtime-from-list>

Warning

A major runtime change, such as a new Puppeteer or Selenium version, can break selectors and helper calls in existing scripts. Test the upgrade on a copy of the canary first, or watch the first runs closely and roll back with update-canary if they fail.

Step 7: confirm it's healthy

aws synthetics start-canary --name "$CANARY"   # only if it is STOPPED
aws synthetics get-canary-runs --name "$CANARY" --max-results 3 \
  --query 'CanaryRuns[].{Start:Timeline.Started,State:Status.State,Reason:Status.StateReason}'

Close the incident once you have three passing runs in a row and new artifacts appearing in S3.

Prevent it next time

  • Alarm on SuccessPercent (namespace CloudWatchSynthetics, dimension CanaryName) with M-of-N evaluation, for example 2 of 3 datapoints. One failed run should not page anyone.
  • Treat EXECUTION_FAILURE as a ticket, not a page. It means the canary's own plumbing broke, not the service it checks.
  • Keep canary roles, artifact buckets and VPC endpoints in the same IaC stack as the canary, so a bucket or endpoint policy change can't quietly break it.
  • Review describe-runtime-versions each quarter and track AWS Health notices for Synthetics runtime deprecations.
  • Set an S3 lifecycle rule on the artifact bucket so screenshots and HAR files don't pile up.