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
posta 3 mesi fa431 visualizzazioni
1 Risposta
2
Risposta accettata

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
ESPERTO
con risposta 3 mesi fa
profile picture
ESPERTO
verificato 3 mesi fa
  • Thanks . I see cfnmodule is only available if we are using ZipFile

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande