I’m using serverless - Lambda (alias and versions) - API gateway
When I change my code and use sls deploy and test my function in postman or browser It gets updated and I can see the change in the response (postman or browser).
BUT when I change my code (added the word captain after hello) and use:
serverless deploy function -f myFunction
The change is not shown in the response (postman). but you can see the change in lambda inline preview and it is also shown when I test it in API gateway under resources option (see image below).
serverless deploy function only updates the code for $LATEST. You need to use the full serverless deploy if you’re updating the CloudFormation template too.
Is there a way to reflect my changes when just deploying a single function?
I was using them to mantain a dev and prod version of my app. Now I’d just change de serverless.yml stage value to deploy my code and test right? It’s a little scary what if by mistake prod stage is deployed and I haven’t test the app yet.
What you probably want are Serverless Framework stages. These are different to API Gateway stages or Lambda aliases because they deploy a complete copy of the environment. This allows you to safely test everything in “test” before deploying to “prod”.
You can also set it during deployment with the -s or --stage command line option. I typically don’t set the stage in the provider section. In the custom section I add:
custom:
stage: ${opt:stage, self:provider.stage}
Then reference ${custom.stage} anywhere I need the current stage in my serverless.yml file. There are variations on this including setting the stage in the provider setting to ${opt:stage, "dev"}