1
votes

I need to automatically delete a cloudformation stack after the EC2 instance created using that stack has finished running its UserData. I have tried to run deletion from the ec2 instance but it gives me permission error as the ec2 instance itself is deleted before deleting the whole stack.

1
Why do you wish to do this? CloudFormation is normally used to deploy long-running infrastructure. If you simply wish to run a job, why not just launch an EC2 instance instead of creating a full CloudFormation stack? Also, what do you mean by "it gives me permission error"? Have you assigned an IAM Role to the instance with sufficient permissions to delete the stack?John Rotenstein

1 Answers

0
votes

I quite don't understand what you want in your question. But in general, if you delete the CloudFormation stack, all the resources created by that stack will also be deleted. All your resources, including EC2, will be deleted first before you can see successful deletion of your CloudFormation stack.