Why doesn't cloudformation support ZipFile inline code option for Python lambdas

0

The documentation for the ZipFile field in the AWS::Lambda::Function CloudFormation structure says that nodejs and Python are both supported. Copying the sample code for nodejs runtimes works just fine, but if you switch the Runtime to any Python runtime (Python3.7 up to Python3.11), the stack creation fails with:

Resource handler returned message: "Invalid request provided: The ZipFile attribute is not supported for the runtime 'Python3.7'" (RequestToken: <redacted>), HandlerErrorCode: InvalidRequest)

Is this an issue with the documentation (and Python runtimes no longer support inline ZipFile) or is there a defect in the CloudFormation process?

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  primer:
      Type: AWS::Lambda::Function
      Properties:
        # Putting nodes18.x (instead of Python3.7, Python3.8, etc.) here works just fine..
        Runtime: Python3.7
        Role: !Sub "arn:aws:iam::${AWS::AccountId}:role/My_Role"
        Handler: index.handler
        Code:
          ZipFile: |
            def handler(event, context):
              return {'statusCode': 200, 'body': 'OK'}
        Description: List Amazon S3 buckets in us-east-1.
        TracingConfig:
          Mode: Active
질문됨 2달 전371회 조회
1개 답변
2
수락된 답변

Hi there,

You might have a typo , you have Python3.7 also python3.7 is no longer supported, to view the supported run-times, check this here

This is a template I just tried with python3.8 and it worked HTH

AWS
jay-aws
답변함 2달 전
profile picture
전문가
검토됨 2달 전
profile pictureAWS
전문가
검토됨 2달 전
  • Thank you so much for responding. That solved it! I wish the CF event errors were more descriptive. I jumped to python3.11.

  • Just for additional help, you could deploy cfn-lint that linter will pick up invalid values in your CFn template before you even deploy it. In this case it picked up the incorrect python in my IDE.

    https://github.com/aws-cloudformation/cfn-lint

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠