Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downgrade to previous version of AWS Lambda

Working with Amazon Lambda functions I use versioning feature which is provided by AWS Lambda functionality. Each time when I deployed new version of my artifact to AWS I create new version of function and publish it (using popup from screenshot).

enter image description here

But how can I publish any previous version of my function (for example when I need to rollback my last publication)?

like image 292
Gleb Avatar asked Apr 27 '18 11:04

Gleb


3 Answers

You should provide each new version with an alias.

From the AWS Documentation

In contrast, instead of specifying the function ARN, suppose that you specify an alias ARN in the notification configuration (for example, PROD alias ARN). As you promote new versions of your Lambda function into production, you only need to update the PROD alias to point to the latest stable version. You don't need to update the notification configuration in Amazon S3.

The same applies when you need to roll back to a previous version of your Lambda function. In this scenario, you just update the PROD alias to point to a different function version. There is no need to update event source mappings.

like image 195
ThomasVdBerge Avatar answered Nov 10 '22 18:11

ThomasVdBerge


In order to rollback to a specific version, you need to point the alias that are assigned to the current version to the version you want to rollback to.

For example: My latest version is 20 and has an alias 'Active'. For me to rollback or remove the version 20, I need to remove the alias or reassign it to another version. So if I point my alias to version 17 then lambda will take the version 17 as the default or prod version.

you can update the alias here:

https://myRegion.console.aws.amazon.com/lambda/home?region=myRegion#/functions/functionName/aliases/Active?tab=graph

(Update myRegion and functionName with relevant values.)

In the above specified page go to 'Aliases' section, click on 'Version' dropdown (by default it will display the version for which the alias is assigned to). Select the version that your alias want to point to and click on save.

Thats All !!!

like image 5
akhi1 Avatar answered Nov 10 '22 19:11

akhi1


One solution I've found that works if your in a pinch is to go to a previous (working) version of lambda, download the deployment package, redeploy the downloaded zip package using the aws cli. I'm sure there is a more elegant solution but if you're in a pinch and you need something right now this works.

$ aws lambda update-function-code \
--function-name my_lambda_function \
--zip-file fileb://function.zip
like image 5
Bryan Grove Avatar answered Nov 10 '22 19:11

Bryan Grove