Having trouble to delete CloudFormation

1

I have trouble deleting AWS stack, using both java SDK and AWS cli.

MVP:

AWSTemplateFormatVersion: "2010-09-09"
Metadata:
    Generator: "former2"
Description: ""

Resources:
    EC2KeyPair:
        Type: "AWS::EC2::KeyPair"
        Properties:
            PublicKeyMaterial: "foo"
            KeyName: "bar"
            KeyType: "rsa"

Deletion attempt KeyPair throws internal error and ends with DELETE_FAILED. After attempting to delete resource for the second time it is succesfull (resource has been fully initalized before first attempt).

Deletion is attempted with least access rights possible (ec2:* ,cloudformation:* ... ), when attempted with admin access delete works on first try.

asked 2 years ago342 views
2 Answers
0

Hi There

Is this key attached to an EC2 instance? is it possible the EC2 instance is not fully terminated before you are attempting to delete the key?

profile pictureAWS
EXPERT
Matt-B
answered 2 years ago
  • there is no EC2 instance being created. YAML snippet from question can be uploaded as is using aws cloudformation deploy command

0

When deletion fails (usually 3 after attempts that take a while), on some resources, the Cloudformaiton stack will delete successfully, even though the reasouce is still there.

If it works with admin, but not with the least privileges role, you correctly assume that this is IAM related.

Usually Cloudformaiton to needs read (ec2:Get*, ec2:List*, ec2:Describe*) permission and manage tags (ec2:DeleteTags and ec2:CreateTags) not only the ec2:DeleteKeyPair permission.

Hope it helps!

profile picture
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions