VOOZH about

URL: https://repost.aws/questions/QUtqrQ6_3zSxmKo3QtFW_4Aw/cfnresponse-package-is-missing-in-new-python-3-9-runtime

⇱ cfnresponse package is missing in new Python 3.9 runtime | AWS re:Post


Skip to content

cfnresponse package is missing in new Python 3.9 runtime

2

Recently, AWS released Lambda runtime for python 3.9! Great!

But I noticed that, used as a backend of Cloudformation custom resource, cfnresponse is not provided.
This might be a bug, or do I miss something?

How to reproduce:
Use the following cloudformation template, and look into CloudWatch Logs for the backend function.

AWSTemplateFormatVersion: '2010-09-09'
Resources:
 BareLambdaFunctionPython39:
 Type: AWS::Lambda::Function
 Properties:
 Runtime: python3.9
 Handler: "index.handler"
 Role: !GetAtt LambdaExecutionRole.Arn
 Code:
 ZipFile: |
 import cfnresponse
 def handler(event, context):
 cfnresponse.send(event, context, cfnresponse.SUCCESS, {})
 BareLambdaFunctionPython39Custom:
 Type: Custom::BareLambdaFunctionPython39
 Properties:
 ServiceToken: !GetAtt BareLambdaFunctionPython39.Arn
 
 LambdaExecutionRole:
 Type: AWS::IAM::Role
 Properties:
 AssumeRolePolicyDocument:
 Version: "2012-10-17"
 Statement:
 - Effect: Allow
 Principal:
 Service:
 - lambda.amazonaws.com
 Action:
 - sts:AssumeRole
 Path: /
 ManagedPolicyArns:
 - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
START RequestId: 96967b62-6969-4005-97ae-4bxxxxxxxxxx Version: $LATEST
[ERROR] Runtime.ImportModuleError: Unable to import module 'index': No module named 'cfnresponse'
Traceback (most recent call last):
END RequestId: 96967b62-6969-4005-97ae-4bxxxxxxxxxx 

Note that there is no error if I use python 3.8 runtime.

Language
English

asked 5 years ago4.6K views

1 Answer
  • Newest
  • Most votes
  • Most comments
1
Accepted Answer

Hi penguin32,

We've identified the issue and have deployed a fix. You should find cfnresponse now works properly for Lambda functions using the Python 3.9 managed runtime. Thanks for bringing this to our attention.

answered 5 years ago

EXPERT

reviewed 2 years ago

  • fbacker
    3 years ago

    This is now missing in 3.10 and 3.11 runtime

  • Lydon
    2 years ago

    Reminder to everyone, you can only import cfnresponse if you are deploying the Lambda and code using Zip in CloudFormation. You cannot just create a Lambda and import.