agutoli / serverless-layers

Serverless.js plugin implementing AWS Lambda Layers, reducing lambda size, warm-up, and deployment time.
MIT License
229 stars 53 forks source link

Wrong layer is used #142

Closed offscriptdev closed 9 months ago

offscriptdev commented 1 year ago

Hello!

I'm encountering an issue where the layers plugin will sometimes revert to an old layer on deployment. Then, of course, running the lambda will fail as the dependency is missing.

Here's my environment:

OS: Linux
Node: v18.16.0
serverless: v3.30.1
serverless-deployment-bucket: 1.6.0
serverless-layers: 2.6.1

Here's the deploy log:

[ LayersPlugin ]: => questionnaire-server
... ○ Downloading ./layers/questionnaire-server/package.json from bucket...
... ○ Comparing package.json dependencies...
... ○  No changes ! Using same layer arn: arn:aws:lambda:us-east-1:*********:questionnaire-server-dev-nodejs-questionnaire-server:13
... ○ Adding layers...
... ✓ function.sendReport - arn:aws:lambda:us-east-1:*********:questionnaire-server-dev-nodejs-questionnaire-server:13

I checked the package.json in S3 and it matches the one in my layers folder. The thing is that layer version should be v15, not v13. Things I've done:

I'm guessing there's a config file somewhere locally that I'm missing that might be corrupted.

I'd appreciate help in the next steps of debugging. Cheers!

offscriptdev commented 1 year ago

Anyone able to look into this, or at least able to point me in the right direction?

offscriptdev commented 1 year ago

I troubleshot this as far as getting the output info from AWS.

It turns out that the CloudFormation stack output had the wrong layer in it. So, the issue doesn't appear to be anything local or with the code to get the current layer from AWS.

It looks like the issue would be with how layers are updated. If I have time later, I'll test this. But if anyone else picks this up, that would be the direction to go for troubleshooting.

agutoli commented 9 months ago

Please try: https://www.npmjs.com/package/serverless-layers/v/2.7.0

offscriptdev commented 9 months ago

Thanks for the update @agutoli

Currently my code should be using layer v17. Prior to updating, it was stuck at using v16.

I updated to serverless-layers v2.7.0 and tested:

Both behaviors above are unexpected. What I was expecting was to use v17. I'll see if I can inject some logging into the plugin and get some more insight into what is going on here.

offscriptdev commented 9 months ago

I've tracked things down to an incorrect CloudFormation stack output: image

Something in the plugin isn't updating the output to the correct (latest) version of my layers. Thus, when CloudFormationService.getOutputs() is called it will return and use the incorrect value from CloudFormation outputs.

offscriptdev commented 9 months ago

I just added a package to my layer to see what happens. The plugin will detect the changes and upload a new version, which is now v19, but the CloudFormation output is not updated and is still v16.

So, the cause of this issue seems to be that CloudFormation outputs are not being updated.

My recommendation is to either update the CloudFormation outputs on layer changes, or to get the layer version from the lambda function instead of the CloudFormation outputs. I'm not sure if that should be handled by this plugin or the parent serverless package. So, I'll leave this in your hands @agutoli