'How to update multiple Lambda functions from python 2.7 to 3.6

I have approximately 13 Lambda functions with triggers on python 2.7 runtime environments. I need to update to 3.6

What is the most efficient way to do this? Do I need to create all new lambdas? If issues arise will I be able to roll back to the 2.7 lambda?

Any help will be greatly appreciated.



Solution 1:[1]

You can try Runtime Settings below your code inside the AWS Management Console for your lambda handler. There you can choose your runtime (eg. Python 3.8 or 2.7). Up to you to fix all back-compatibility issues.

Obviously, this means you need to do this for each one of your handlers. A better way, if you aren't doing this already is to use serverless and deploy your stack from a serverless.yaml configuration file.

Beware that from mid-July 2021 AWS will start the 1st phase of their end of python 2.7 support. So, for a more future-proof solution, good to take this under consideration.

Hope this helps a bit.

Solution 2:[2]

If you want to do it the manual way go to the Lambda Console -> Actions -> Export Function -> Download Deployment Package. This will download a zip with the Lambda and any supporting libraries. This process can be reversed by createing a new Lambda with the correct name and role and runtime and then the Upload From -> .zip file option. This is how you can backup the Lambda's and re-instate them manually.

To update the runtime, just go into the Lambda console -> Code and Scroll to Runtime Settings to change the runtime. Depending what code your Lambda has jumping from Python 2 to 3 will probably not run - so just changing the runtime might not be the onlything you need to do.

If you want to script the update of the runtime then you can use the CLI command like this:

aws lambda update-function-configuration --function-name "YourFunctionName" --runtime "python3.6"

Solution 3:[3]

As @markonic said, you need handling of your code to be compatible with python3.X.

But about only to changing your lambda runtime of 2.7 to 3.6 you can use the command below:

 aws lambda --region 'us-east-1' update-function-configuration \
--function-name ArnOfYourFunction \
--runtime python3.6

You can use the same command to rollback to python2.7 changing the parameters

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Markonick
Solution 2
Solution 3 Luciano Marqueto