cloud jockey
cloud jockey

Reputation: 258

AWS: Delete lambda layer still retains layer version history

I am deploying a AWS Lambda layer using aws cli:

aws lambda publish-layer-version --layer-name my_layer --zip-file fileb://my_layer.zip

I delete it using

VERSION=$(aws lambda list-layer-versions --layer-name my_layer | jq '.LayerVersions[0].Version'
aws lambda delete-layer-version --layer-name my_layer --version-number $VERSION

Deletes successfully, ensured no other version of the layer exists.

aws lambda list-layer-versions --layer-name my_layer
>
{
    "LayerVersions": []
}

Upon next publishing of the layer, it still retains history of previous version. From what I read if no layer version exists and no reference exists, the version history should be gone, but I don't see that. Anybody have a solution to HARD delete the layer with its version?

Upvotes: 12

Views: 8194

Answers (5)

drieck
drieck

Reputation: 11

https://docs.aws.amazon.com/lambda/latest/dg/creating-deleting-layers.html

When you delete a layer version, you can no longer configure a Lambda function to use it. However, any function that already uses the version continues to have access to it. Also, Lambda never reuses version numbers for a layer name.

In order to do so AWS needs to keep some (internal) memory of the "deleted" layer (versions). AFAIK there is no way to remove these references.

Upvotes: 0

Satya Vinay
Satya Vinay

Reputation: 361

I am facing the same issue, As there was no aws-cli command to delete the layer itself,I had delete all versions of my lambda-layer using:

aws lambda delete-layer-version --layer-name test_layer --version-number 1

After deleting all versions of the layer, the layer was not showing in aws lambda layers page,So I thought its successfully deleted.

But to my surprise,AWS stills keeps the data about our deleted layers(at-least the last version for sure), when you try create a lambda layer with your previous deleted lambda name using aws gui or cli, the version will not start from 1, instead it starts from last_version of assumed to be deleted layer.

Upvotes: 2

Federico Boschini
Federico Boschini

Reputation: 81

I have the same problem. What I'm trying to achieve is to "reset" the version count to 1 in order to match code versioning and tags on my repo. Currently, the only way I found is to publish a new layer with a new name.

I think AWS Lambda product lacks of features that help (semantic) versioning.

Upvotes: 6

Sudhir Nallagangu
Sudhir Nallagangu

Reputation: 41

I ran into similar problem with layer versions. Do you have suggestions for simple way out instead of writing code to check available versions out there and pick latest one...

Upvotes: 2

keithRozario
keithRozario

Reputation: 406

Currently there's no way to do this. Layer Versions are immutable, they cannot be updated or modified, you can only delete and publish new layer versions. Once a layer version is 'stamped' -- there is no way (AFAIK) that you can go back and get back that layer version.

It might be that after a while (weeks...months?) AWS delete it's memory of the layer version, but as it stands, the version number assigned to any deleted layer cannot be assumed by any new layer.

Upvotes: 3

Related Questions