Home / AWS

AWSTroubleshootingAdvanced

SSM State Manager association failed or stuck in Pending - find the failing nodes and fix them

Find out why a State Manager association shows Failed or Pending, drill down from the association to a single instance, read the real error and re-run safely.

Deepak Bhardwaj5 min read

Applies toAWS Systems Manager State Manager, SSM Agent 3.x on Amazon Linux, Ubuntu, RHEL and Windows Server, AWS CLI v2

Symptom

A State Manager association, for example one that installs the CloudWatch agent, runs an inventory or enforces a config script, shows Failed or stays Pending in the console. Configuration compliance says some nodes are non-compliant. Nobody knows which instances failed or why.

State Manager has three layers. Work through them in order:

  1. Association: the document, targets, schedule and rate controls.
  2. Execution: one run of the association.
  3. Execution target: the result on one managed node, with its own output.

Step 1: find the failing associations

aws ssm list-associations \
  --query "Associations[].{Id:AssociationId,Name:Name,Doc:Name,Status:Overview.Status,Detail:Overview.DetailedStatus,Last:LastExecutionDate}" \
  --output table

Read the full definition of the one you care about:

aws ssm describe-association --association-id <assoc-id> \
  --query "AssociationDescription.{Doc:Name,Version:DocumentVersion,Targets:Targets,Schedule:ScheduleExpression,MaxConc:MaxConcurrency,MaxErr:MaxErrors,Output:OutputLocation,Counts:Overview.AssociationStatusAggregatedCount}"

AssociationStatusAggregatedCount shows how many nodes are in each status. That tells you whether one instance or the whole fleet is affected.

Step 2: find the execution and the failing targets

aws ssm describe-association-executions --association-id <assoc-id> \
  --max-results 5 \
  --query "AssociationExecutions[].{Exec:ExecutionId,Status:Status,Detail:DetailedStatus,Created:CreatedTime,Counts:ResourceCountByStatus}"

Then list the nodes where that run failed:

aws ssm describe-association-execution-targets \
  --association-id <assoc-id> --execution-id <exec-id> \
  --filters Key=Status,Value=Failed \
  --query "AssociationExecutionTargets[].{Node:ResourceId,Status:Status,Detail:DetailedStatus,Output:OutputSource.OutputUrl}"

From the instance side, see every association on one node:

aws ssm describe-instance-associations-status --instance-id i-0abc123def4567890 \
  --query "InstanceAssociationStatusInfos[].{Assoc:AssociationId,Name:Name,Status:Status,Detail:DetailedStatus,Error:ErrorCode,Exec:ExecutionSummary,Out:OutputUrl.S3OutputUrl.OutputUrl}"

ErrorCode and ExecutionSummary usually hold the first useful clue. The exact text depends on the document and the agent version.

Step 3: read the real error

The association status only tells you that a step failed. The step output tells you why.

  • Output location set: open the S3 URL from step 2. Each plugin writes stdout and stderr.
  • No output location: read the agent logs on the node, through Session Manager if it still works:
# Linux
sudo tail -n 200 /var/log/amazon/ssm/amazon-ssm-agent.log
sudo grep -i association /var/log/amazon/ssm/errors.log | tail -n 50
sudo ls /var/lib/amazon/ssm/<instance-id>/document/orchestration/
# Windows
Get-Content "C:\ProgramData\Amazon\SSM\Logs\amazon-ssm-agent.log" -Tail 200
Select-String -Path "C:\ProgramData\Amazon\SSM\Logs\errors.log" -Pattern "association" | Select-Object -Last 50

The orchestration folder holds the per-run plugin output (stdout/stderr). The folder layout varies by agent version, so look for the newest folder.

Status → cause → fix

What you see Likely cause Fix
Whole fleet Pending and never runs Nodes aren't managed (offline, no instance profile, no route to SSM endpoints) aws ssm describe-instance-information must list the node as Online. Fix the agent, role or VPC endpoints first
Some nodes Pending forever Targets match nodes that are stopped, or the association runs only on its schedule (ApplyOnlyAtCronInterval) Start the node or wait for the next interval. Use start-associations-once to run it now
Execution stops after a few failures, the rest show Skipped or no result MaxErrors reached, so State Manager stops sending to more targets Fix the root cause on the failed nodes, then re-run. Raise MaxErrors only if partial failure is acceptable
Failed with a non-zero exit code The script in the document failed: package not found, proxy, wrong OS Read stderr and test the command by hand on one node
Failed with an S3 or download error Instance role can't read the S3 or GitHub source used by AWS-RunRemoteScript or AWS-ApplyAnsiblePlaybooks, or there's no egress Grant s3:GetObject on the source, add an S3 gateway endpoint or allow egress
Failed, document not supported on this platform A Linux document targeted a Windows node, or the other way round Narrow the targets with tags per OS, or use a document that supports both
Runs again and again and changes the server each time Script not idempotent Rewrite it to check the current state before it changes anything
Failed right after a document update DocumentVersion set to $LATEST and the new version is broken Pin to $DEFAULT or a known-good version number

Step 4: fix and re-run

After the fix, trigger the association once instead of waiting for the schedule:

aws ssm start-associations-once --association-ids <assoc-id>

Pin the document version and set safe rate controls:

aws ssm update-association --association-id <assoc-id> \
  --document-version 3 \
  --max-concurrency 10% --max-errors 5% \
  --output-location "S3Location={OutputS3BucketName=ssm-assoc-output-111122223333,OutputS3KeyPrefix=state-manager/}"

Warning

update-association usually starts a new run on all targets straight away, unless --apply-only-at-cron-interval is set. If the document restarts services or reboots, check your rate controls before you save the change.

Caution

Don't fix a failing association by setting --max-errors 100%. A broken script will then run on every node in the target set, including production.

Step 5: confirm with compliance

State Manager reports into configuration compliance with the Association compliance type:

aws ssm list-compliance-summaries \
  --filters Key=ComplianceType,Values=Association,Type=EQUAL

aws ssm list-resource-compliance-summaries \
  --filters Key=ComplianceType,Values=Association,Type=EQUAL Key=OverallSeverity,Values=CRITICAL,Type=EQUAL \
  --query "ResourceComplianceSummaryItems[?Status=='NON_COMPLIANT'].ResourceId"

aws ssm list-compliance-items --resource-ids i-0abc123def4567890 \
  --resource-types ManagedInstance \
  --filters Key=ComplianceType,Values=Association,Type=EQUAL

Set --compliance-severity on the association (CRITICAL, HIGH, MEDIUM, LOW) so that critical baselines show up first.

Prevent it next time

  • Always set an --output-location, so you can read failures from S3 without logging in to the node.
  • Pin --document-version and roll out new versions to a small tagged canary group first.
  • Use percentage-based --max-concurrency and a low --max-errors on production targets.
  • Send State Manager association state changes to EventBridge and alert on failures. Check the current event detail type names in the EventBridge console for Systems Manager.
  • Write scripts that are idempotent and exit non-zero on real failure, so the association status tells the truth.