python - How to import any lib from zip lambda layer despite nesting libs properly - Stack Overflow

I did try the 2 solutions - nesting properly my Python libs inside zip folder:layer_content.zip└ pyth

I did try the 2 solutions - nesting properly my Python libs inside zip folder:

layer_content.zip
└ python
    └ lib
        └ python3.11
            └ site-packages
                └ requests
                └ <other_dependencies> (i.e. dependencies of the requests package)
                └ ...

and following another tip that Amazon just changed its requirement and all libs should go directly into python folder. But both options don't work.

my_layer.zip:
  - python
     - requests
     - psycopg2
     - snowflake-connector

my_layer_nested.zip:
    └ python
        └ lib
            └ python3.11
                └ site-packages
                    └ requests
                    └ snowflake-connector
                 

Neither work, it does not see the requests module:

import json
import requests



def lambda_handler(event, context):
    url = ";
    response = requests.get(url)
    
    return {
        'statusCode': 200,
        'body': json.dumps({
            'message': 'Layer test successful!',
            'data': response.json()
        })
    }
                

I tried using both separate zip folders as layers, here is the output:

Status: Failed
Test Event Name: kljlj

Response:
{
  "errorMessage": "Unable to import module 'lambda_function': No module named 'requests'",
  "errorType": "Runtime.ImportModuleError",
  "requestId": "",
  "stackTrace": []
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744663247a4586591.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信