Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to track which git branch is currently deployed in AWS lambda?

The problem

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.

like image 661
M K Avatar asked Oct 26 '25 01:10

M K


1 Answers

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:

  1. Checkout to the branch you want to deploy and make the required changes. Once the changes are done do serverless deploy
  2. Wait for deployment to complete
  3. Go to the deployed lambda and select action->create alias
  4. Enter the alias name which should be the branch name from where the code was deployed
  5. Select the latest or desired version number and click create

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

like image 96
Terence Nero Avatar answered Oct 27 '25 15:10

Terence Nero