serverless: Lambda layer versions are not being retained
Bug Report
Description
- What did you do?
Deployed a layer-only service with
retain: true - What happened? Previous layer version is deleted
- What should’ve happened?
Since
retainis set totrue, the previous layer version should still be available - What’s the content of your
serverless.ymlfile?
service: config-layer
provider:
name: aws
profile: personal
layers:
config:
path: ./
retain: true
compatibleRuntimes:
- nodejs10.x
- What’s the output you get when you use the
SLS_DEBUG=*environment variable (e.g.SLS_DEBUG=* serverless deploy) debug.txt
Similar or dependent issues:
In PR #6545, S3 key was removed from the sha hash, which results in the same logical id with every deployment. I believe cloudformation removes versions with the same logical id, regardless of DeletionPolicy: Retain being set.
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 19
- Comments: 29 (4 by maintainers)
I’m interested too, what are next steps on this?
Any news on this one?
Will there be any fix soon?
I am fairly new to using layers in serverless. I am quite surprised that this bug still exists. In particular, we have issues when we deploy our lambdas (using Atlassian Bamboo as our CI/CD) which depend on layers in another Cloudformation stack (centralized), and then we need to roll back the release. Since the lambda layers are not being retained, the rollback fails.
I have seen the workaround of going back to serverless 1.43.0, but I am currently on 1.60.4, so I am worried about the impact of reverting back to a version that was ages ago.
It seems we are lacking some leadership/ownership on this issue. I am not sure there is someone who can step forward and take ownership and get this fixed. I am willing to head that up if no one else is, but I am not sure I am the most qualified. It does seem like a fairly simple issue of just passing this through so that the DeletionPolicy is set to “Retain” on the Cloudformation, but I am probably oversimplifying.
Any news on this?
Can someone please explain why I should override the UpdateReplacePolicy in the Resources section instead of relying on the
retainproperty of the layer? I’m getting an error that the stack cannot be updated because a layer ref is in use by another stack:Which is the official solution?
https://github.com/serverless/serverless/issues/7353
@RenatoFranze , This worked perfectly for me. Thanks!
Indeed, @daninfpj , it was my mistake with the resource name. Thank you very much!
@RenatoFranze I think that error is unrelated to this specific issue. It’s telling you that you need to define a type for your resource.
In the example I posted, I don’t do that explicitly because the layer definition already does it, but I’m not sure if you’re doing that or if you’re referring correctly to your layer. In the example, a
configentry in thelayerskey generates aConfigLambdaLayerresource, that already has aType, and I only addUpdateReplacePolicy: Retainto it.There’s a work-around for this posted here for python-based layers