DEV Community

Cover image for How to fix "failed to delete stack: Role ... is invalid or cannot be assumed" in AWS CloudFormation
David J Eddy
David J Eddy

Posted on

5 4

How to fix "failed to delete stack: Role ... is invalid or cannot be assumed" in AWS CloudFormation

Cross posted from my blog.

The Situation

In the recent weeks most of my day job time has been spent with CloudFormation (CF) and the AWS developer tools. CodeStar, CodeBuild, CodePipeline, and CodeDeploy. During the day-in / day-out routine I came across a error that stumped me for a bit; When deleting a CF stack the follow error message was returned and the stack was not deleted.

failed to delete stack: Role [...] is invalid or cannot be assumed 

Sobering thought of the day: one day we will all be fossils.

The Solution

The error message text is fairly clear, though not very detailed. In layman's terms when the CF service attempts to assuming an IAM role in order to complete a task the role (in my case) no longer exists. After a bit of digging I found a solution and it is surprisingly reasonable!

  • Go to the IAM service; we want to create a new role
  • Then create a role names as the missing role from the error message
  • Then assign access policies that the role will need
    • In my case I was trying to delete the stack; and while not a best practice, the admin role was sufficient.
  • Then execute the CF process once more

If all goes well the stack should complete the desired action (delete) with without issue. The solution really is that easy. #win

All good graphs go up and to the right.

Wrapping Up

Hopefully you find this helpful in your dealings with AWS, now or in the future. Do you have any quick tips concerning AWS CloudFormation? What has your experience with CF been like? Let me know in the comments below.

👋 While you are here

Reinvent your career. Join DEV.

It takes one minute and is worth it for your career.

Get started

Top comments (3)

Collapse
 
sivaramsajeev profile image
sivaramsajeev •

Great post. This is another method to clean up the stuck stacks
gist.github.com/sivaramsajeev/9d47...

Collapse
 
tmaximini profile image
Thomas Maximini •

Thanks, that helped a lot!

Collapse
 
scottnightingale profile image
scott-nightingale •

Thanks David, very helpful

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay