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.

gefragt vor 2 Jahren348 Aufrufe
2 Antworten
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
EXPERTE
Matt-B
beantwortet vor 2 Jahren
  • 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
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen