Resolving AWS Lambda runtime deprecation errors in CloudFormation to ensure successful stack deployments and updates.
Description:
When creating a new CloudFormation stack or updating an existing one with Lambda functions, you receive the following error: The runtime parameter of [RUNTIME_NAME] is no longer supported for creating or updating AWS Lambda functions. The root cause is typically related to using outdated runtime versions that AWS has phased out of service. For example, if your Lambda function is using an older Node.js version like 10.x or Python 2.7, you will encounter this error as these runtimes are no longer supported by AWS Lambda's service infrastructure.
AWS Lambda periodically deprecates older runtimes as their underlying frameworks or languages reach end-of-life or end-of-support. This deprecation ensures security compliance, maintains performance standards, and enables access to the latest language features and security patches. This error occurs when your CloudFormation template includes a Lambda function using a deprecated runtime, whether you're creating a new stack or updating an existing one. You need to update your template to use a supported runtime version.
Resolution:
- Update the Lambda Function Runtime
- Locate the CloudFormation stack which got failed to create or update the Lambda function with error mentioned above.
- In your CloudFormation template, locate the AWS::Lambda::Function resource.
- Modify the “Runtime“ property to use a supported runtime version.
- List of supported Runtime property can be found here
- For SAM templates, update AWS::Serverless::Function.
Example template with deprecated runtime:
AWSTemplateFormatVersion: "2010-09-09"
Resources:
DummyServer:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: |
def handler(event, context):
print(event)
return "Hello from lambda"
Handler: "index.handler"
Role: "arn:aws:iam::123456789012:role/lambda-role"
Runtime: "python3.6"
- Use the updated template to create a new stack or Update an existing stack.
- The CloudFormation operation should now complete successfully.
Note: When upgrading Lambda function runtimes, assess all dependencies in both your deployment package and Lambda Layers, and ensure layers are created on the same OS as your target runtime. More information on runtimes can be found here
Tips:
- Use cfn-lint to validate your CloudFormation templates and catch runtime compatibility issues before deployment
- You can also opt in to receive a runtime deprecation notifications from AWS for existing lambda functions
Co-Author: Sercan Dogan