How to fix "failed to delete stack: Role ... is invalid or cannot be assumed" in AWS CloudFormation
Tags: aws, devops, quicktip, todayilearned
Published: 2019-01-10 13:58:22

---
title: 'How to fix "failed to delete stack: Role ... is invalid or cannot be assumed" in AWS CloudFormation'
published: true
description: 'How to fix the "failed to delete stack: Role [...] is invalid or cannot be assumed" error when using AWS CloudFormation.'
tags: #aws #devops #quick-tip #til
cover_image: https://blog.davidjeddy.com/wp-content/uploads/2019/01/aws_happy_cloud_med.png
---

Cross posted from my [blog](https://blog.davidjeddy.com/2019/01/10/how-to-fix-failed-to-delete-stack-role-is-invalid-or-cannot-be-assumed/).

<!-- wp:heading -->
<h2>The Situation</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In the recent weeks most of my day job time has been spent with <a href="https://aws.amazon.com/cloudformation/">CloudFormation </a>(<a href="https://aws.amazon.com/cloudformation/">CF</a>) and the AWS developer tools. <a href="https://aws.amazon.com/codestar/">CodeStar</a>, <a href="https://aws.amazon.com/codebuild/">CodeBuild</a>, <a href="https://aws.amazon.com/codepipeline/">CodePipeline</a>, and <a href="https://aws.amazon.com/codedeploy/">CodeDeploy</a>. During the day-in / day-out routine I came across a error that stumped me for a bit; When deleting a <a href="https://aws.amazon.com/cloudformation/">CF</a> stack the follow error message was returned and the stack was not deleted.</p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">failed to delete stack: Role [...] is invalid or cannot be assumed </pre>
<!-- /wp:preformatted -->

<!-- wp:image {"id":1361,"align":"center","width":498,"height":664} -->
<div class="wp-block-image"><figure class="aligncenter is-resized"><img src="https://blog.davidjeddy.com/wp-content/uploads/Chad_Hagan_Art_and_Design/Nautilus/Nautilus_Anthropocene.jpg" alt="" class="wp-image-1361" width="498" height="664"/><figcaption>Sobering thought of the day: one day we will all be fossils.</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>The Solution</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The error message text is fairly clear, though not very detailed. In layman's terms when the <a href="https://aws.amazon.com/cloudformation/">CF</a> service attempts to assuming an <a href="https://aws.amazon.com/iam/">IAM</a> 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!</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li> Go to the <a href="https://aws.amazon.com/iam/">IAM</a> service; we want to create a new role</li><li><a href="https://www.youtube.com/channel/UCPSfjD7o1CQZXzdAy56c8kg">Then</a> create a role names as the missing role from the error message</li><li><a href="https://www.youtube.com/channel/UCPSfjD7o1CQZXzdAy56c8kg">Then</a> assign access policies that the role will need<ul><li>In my case I was trying to delete the stack; and while not a best practice, the admin role was sufficient.</li></ul></li><li><a href="https://www.youtube.com/channel/UCPSfjD7o1CQZXzdAy56c8kg">Then</a> execute the <a href="https://aws.amazon.com/cloudformation/">CF</a> process once more</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>If all goes well the stack should complete the desired action (delete) with without issue. The solution really is that easy. #win</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1347,"align":"center","width":531,"height":478} -->
<div class="wp-block-image"><figure class="aligncenter is-resized"><img src="https://blog.davidjeddy.com/wp-content/uploads/Chad_Hagan_Art_and_Design/fortune-Magazine/Fortune_Global.jpg" alt="" class="wp-image-1347" width="531" height="478"/><figcaption>All good graphs go up and to the right.</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>Wrapping Up</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Hopefully you find this helpful in your dealings with AWS, now or in the future. Do you have any quick tips concerning AWS <a href="https://aws.amazon.com/cloudformation/">CloudFormation</a>? What has your experience with CF been like? Let me know in the comments below.</p>
<!-- /wp:paragraph -->