module cfnresponse doesn't exist for Python 3.12

0

Hi In my lambda code I am importing cfnresponse, which will be used in CloudFormation. I am getting the following error in my lambda implemented in Python 3.12 "Unable to import module '" : No module named 'cfnresponse'". I think, cfnresponse module is missing in Python 3.12. Please help me in resolving this issue. Thank you.

AWS
feita há 3 meses431 visualizações
1 Resposta
2
Resposta aceita

Hello.

I tried running the CloudFormation template below and confirmed that Lambda was executed successfully.
I ran it in the Tokyo region.
It's possible that the issue is region-specific, so please try deploying the template below in the region you're using and see if you can reproduce the issue.

By the way, as commented in the URL below, "cfnresponse" can only be used when deploying Lambda and code using Zip with CloudFormation.
https://repost.aws/questions/QUtqrQ6_3zSxmKo3QtFW_4Aw/cfnresponse-package-is-missing-in-new-python-3-9-runtime#CO4K6fg1FGTMyq34g7Igzy_Q

AWSTemplateFormatVersion: "2010-09-09"

Resources:
  SampleLambda:
    Type: Custom::SampleLambda
    Properties:
      ServiceToken: !GetAtt "LambdaFunction.Arn"
      Hoge: "hoge"

  LambdaFunction:
    Type: AWS::Lambda::Function
    Properties:
      Role: !GetAtt "LambdaExecutionRole.Arn"
      Runtime: "python3.12"
      Handler: index.lambda_handler
      Timeout: "180"
      Code:
        ZipFile: |
          import cfnresponse

          def lambda_handler(event, context):
              hoge = event['ResourceProperties']['Hoge']
              if event['RequestType'] == 'Create':
                  print('Create:'+hoge)
                  cfnresponse.send(event, context, cfnresponse.SUCCESS,
                                      {'Response': 'Success'})
              if event['RequestType'] == 'Delete':
                  print('Delete:'+hoge)
                  cfnresponse.send(event, context, cfnresponse.SUCCESS,
                                      {'Response': 'Success'})
              if event['RequestType'] == 'Update':
                  print('Update:'+hoge)
                  cfnresponse.send(event, context, cfnresponse.SUCCESS,
                                      {'Response': 'Success'})

  LambdaExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service:
                - lambda.amazonaws.com
            Action:
              - sts:AssumeRole
      Path: /
      Policies:
        - PolicyName: sample-lambda-policy
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Action:
                  - logs:CreateLogGroup
                  - logs:CreateLogStream
                  - logs:PutLogEvents
                Resource: arn:aws:logs:*:*:*
profile picture
ESPECIALISTA
respondido há 3 meses
profile picture
ESPECIALISTA
avaliado há 3 meses
  • Thanks . I see cfnmodule is only available if we are using ZipFile

Você não está conectado. Fazer login para postar uma resposta.

Uma boa resposta responde claramente à pergunta, dá feedback construtivo e incentiva o crescimento profissional de quem perguntou.

Diretrizes para responder a perguntas