As there are multiple developers working on one project, a problem arises where more than one git branch of source exists. Each branch has the same environment config but may also vary by the feature being developed.
What is the best practice to track, which branch is currently deployed in AWS Lambda?
We use Serverless to handle the deployment and also Gitlab as git storage engine.
A way that I have achieved this in my projects is by using Lambda aliases and versions.
Every time a lambda is deployed the version number is incremented and the latest lambda deployed is tagged as $LATEST.
The versions are unique and are bumped every time a deployment is made to the lambda function irrelevant to which branch you will deploy the code from.
The process for utilizing branch names as Alias to point to a specific version:
Once the alias is created you can invoke the lambda using the lambda name.
If you want to invoke the lambda from ApiGateway you can follow the steps mentioned in this article: Using API Gateway stage variables to manage Lambda functions
Since you are using the serverless framework the steps that I have mentioned above can be done using the Serverless AWS alias plugin
The plugin automates all of the steps that I have mentioned above including creating a stage for every alias.
You can refer to this example for using branch name as aliases
All you have to do is add the --alias=<ALIAS_NAME> flag with the serverless deploy command.
E.g: sls deploy --alias=feature-test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With