CloudFormation Error: 'Resource handler returned message: ... (HandlerErrorCode: InvalidRequest)' — Cause, Fix, and Troubleshooting Guide
Decode the CloudFormation error 'Resource handler returned message: ... (HandlerErrorCode: InvalidRequest)' using RequestToken and handler codes.
- #iac
- #infrastructure-as-code
- #cloudformation
- #troubleshooting
Stuck on this Infrastructure as Code error? Get the free incident triage checklist
A one-page PDF — the exact steps to isolate, fix, and verify a production error like this one. No spam, unsubscribe anytime.
Overview
Resource handler returned message is the wrapper CloudFormation puts around an error that a resource provider (the “handler”) reported while creating, updating, or deleting a resource. Modern CloudFormation resource types run on the registry/handler framework, and when the underlying service API rejects the request, the handler surfaces the service’s message plus a normalized HandlerErrorCode and a RequestToken.
You will see it in the stack events and CLI output:
Resource handler returned message: "The security group 'sg-0123456789abcdef0' does not exist
in VPC 'vpc-0abc123'." (RequestToken: a1b2c3d4-5678-90ab-cdef-EXAMPLE11111,
HandlerErrorCode: InvalidRequest)
This is not one specific bug — it is a generic envelope. The value is in learning to read it: the quoted message is the real cause (from the target service), HandlerErrorCode tells you the class of failure, and RequestToken lets you correlate with CloudTrail. Fix the quoted message and the error goes away.
Symptoms
- A
CREATE_FAILED/UPDATE_FAILEDevent withResource handler returned message: "...". - A
HandlerErrorCodesuch asInvalidRequest,AlreadyExists,AccessDenied,ResourceConflict,NotFound, orThrottling. - The stack rolls back after the handler error.
- The quoted message names a specific downstream resource (a security group, IAM role, subnet, bucket, etc.).
aws cloudformation describe-stack-events --stack-name MyAppStack --region us-east-1
ResourceStatus: CREATE_FAILED
ResourceStatusReason: Resource handler returned message: "..." (HandlerErrorCode: InvalidRequest)
Common Root Causes
The HandlerErrorCode narrows things down fast:
1. InvalidRequest — the service rejected the parameters
Bad or inconsistent inputs: a referenced resource in the wrong VPC, an invalid enum value, a property combination the service does not allow.
"The security group ... does not exist in VPC ..." (HandlerErrorCode: InvalidRequest)
2. AccessDenied — the handler lacks IAM permission
CloudFormation (or the role passed to it) cannot call the underlying API.
"User: arn:aws:sts::123456789012:assumed-role/... is not authorized to perform: ec2:CreateTags"
(HandlerErrorCode: AccessDenied)
3. AlreadyExists / ResourceConflict — name or state collision
A fixed physical name is taken, or the resource is being modified concurrently.
"Table already exists: my-table" (HandlerErrorCode: AlreadyExists)
4. NotFound — a dependency does not exist
A referenced subnet, role, or parameter was deleted out-of-band or never created.
"Role arn:aws:iam::123456789012:role/app-role not found" (HandlerErrorCode: NotFound)
5. Throttling — API rate limits
Large stacks hammering a service API get throttled and the handler surfaces it.
"Rate exceeded" (HandlerErrorCode: Throttling)
6. GeneralServiceException / InternalFailure — downstream service error
A transient or service-side problem, often retryable.
How to Diagnose
Read the full event reason, untruncated
aws cloudformation describe-stack-events \
--stack-name MyAppStack --region us-east-1 \
--query "StackEvents[?ResourceStatus=='CREATE_FAILED'].[LogicalResourceId,ResourceStatusReason]" \
--output text
The quoted string is the actual error — treat everything else as envelope.
Correlate the RequestToken in CloudTrail
aws cloudtrail lookup-events \
--lookup-attributes AttributeKey=ResourceName,AttributeValue=MyAppStack \
--region us-east-1
Match the failing API call and its own error to see exactly which service rejected the request.
Identify the failing resource and its type
aws cloudformation describe-stack-resources \
--stack-name MyAppStack --region us-east-1 \
--query "StackResources[?ResourceStatus=='CREATE_FAILED']"
Reproduce the underlying API call
Once you know the service and parameters, call the API directly to get a cleaner message.
aws ec2 describe-security-groups --group-ids sg-0123456789abcdef0 --region us-east-1
Fixes
Fixes are dictated by the HandlerErrorCode:
InvalidRequest
Correct the offending property. In the VPC example, point the security group and the resource at the same VPC, or fix the referenced ID.
Resources:
MyInstance:
Type: AWS::EC2::Instance
Properties:
SecurityGroupIds: [ !Ref AppSecurityGroup ] # SG must be in the same VPC/subnet
SubnetId: !Ref AppSubnet
AccessDenied
Grant the missing action to the deploying role (or the stack’s service role).
{ "Effect": "Allow", "Action": "ec2:CreateTags", "Resource": "*" }
AlreadyExists / ResourceConflict
Remove the hard-coded physical name (let CloudFormation generate one) or delete/import the orphaned resource.
NotFound
Recreate or correctly reference the missing dependency; add a DependsOn if it is an ordering issue.
Throttling
Add retries via DependsOn to serialize creation, reduce parallelism, or request a service quota increase.
DependsOn: PreviousResource # serialize to reduce concurrent API calls
What to Watch Out For
- Always read the quoted message first — the
HandlerErrorCodeis a category, not the cause. - Keep the
RequestToken; it is the fastest way to find the matching CloudTrail entry when the message is vague. InvalidRequestis frequently a cross-reference mismatch (VPC/subnet/AZ), not a syntax error in your template.- A handler error triggers rollback; fix the root cause before retrying or you may hit
UPDATE_ROLLBACK_FAILED. - Transient
Throttling/InternalFailurecodes are often resolved by simply retrying the deploy.
Related Guides
- CloudFormation ‘CREATE_FAILED … already exists in stack’
- CloudFormation UPDATE_ROLLBACK_FAILED
- CloudFormation Circular Dependency Error
Fixed it? Get 500 Infrastructure as Code & DevOps AI prompts — free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.
Stuck on this? Start guided troubleshooting
Open an interactive diagnostic session with this error already loaded. Work a step-by-step plan, record what each check returns, land on a root cause, and export a clean incident summary — no account needed to start.
Did this fix your issue?
Solved it a different way?
Share the fix that worked for you — reviewed, then published to help the next engineer.
That looks like it may contain a secret (key, token, password, or connection string). Please remove it — a note with a detected secret can’t be published.
Thanks — that helps. Published notes appear after a quick review.
Trending errors this week
The error guides other engineers are actually reading right now.
- 1mount: wrong fs type, bad option, bad superblock
- 2Docker 'failed to set up container networking': Fix the Bridge and IP Pool
- 3Docker 'failed to create shim task': How to Fix the containerd Runtime Error
- 4Transport endpoint is not connected
- 5modprobe: FATAL: Module not found
- 6mount: wrong fs type, bad option, bad superblock
Get 500 Battle-Tested DevOps AI Prompts — Free
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.