简体   繁体   English

无法导入模块“lambda_function”:没有名为“aws_xray_sdk”的模块

[英]Unable to import module 'lambda_function': No module named 'aws_xray_sdk'

I am trying to implement this AWS Lambda Rest API Handler in my lambda code to handle proper response code.我正在尝试在我的 lambda 代码中实现此AWS Lambda Rest API 处理程序以处理正确的响应代码。 For this I needed to repackage the library aws_lambda_powertools and add as a layer in lambda function.为此,我需要重新打包库aws_lambda_powertools并添加为 lambda function 中的一个层。

All the import related to this lib below are working.下面与此库相关的所有导入均有效。

from aws_lambda_powertools import Logger, Tracer
from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from aws_lambda_powertools.logging import correlation_paths
from aws_lambda_powertools.utilities.typing import LambdaContext

But When I am creating object of above Tracer class below its giving error(Rest two commented object logger and app are working fine.但是当我在其给出的错误下方创建 object 以上 Tracer class 时(其余两个评论 object loggerapp工作正常。

tracer = Tracer()
# logger = Logger()
# app = APIGatewayRestResolver()

Error I am getting while declaring tracer object is below:我在声明跟踪器 object 时遇到的错误如下:

Response
{
  "errorMessage": "Unable to import module 'lambda_function': No module named 'aws_xray_sdk'",
  "errorType": "Runtime.ImportModuleError",
  "stackTrace": []
}
Function Logs
OpenBLAS WARNING - could not determine the L2 cache size on this system, assuming 256k
START RequestId: ae8b006b-e7f7-495b-99a0-eb5231c3f81c Version: $LATEST
[ERROR] Runtime.ImportModuleError: Unable to import module 'lambda_function': No module named 'aws_xray_sdk'
Traceback (most recent call last):

I tried to install pip install aws_xray_sdk and repackaged it and re-added to layer still its giving the same error.我尝试安装pip install aws_xray_sdk并将其重新打包并重新添加到层中,但仍然出现相同的错误。

Can anyone help me with this?谁能帮我这个? I am new to lambda. Thanks in advance.我是 lambda 的新用户。提前致谢。

Fixed the error by using AWS Arn arn:aws:lambda:{region}:017000801446:layer:AWSLambdaPowertoolsPythonV2:18 instead of using my own custom repackaged library layer.通过使用 AWS Arn arn:aws:lambda:{region}:017000801446:layer:AWSLambdaPowertoolsPythonV2:18而不是使用我自己的自定义重新打包库层修复了错误。

Reference Link: https://awslabs.github.io/aws-lambda-powertools-python/2.6.0/参考链接: https://awslabs.github.io/aws-lambda-powertools-python/2.6.0/

Tracing (like validation and parsing) requires additional dependencies.跟踪(如验证和解析)需要额外的依赖项。 They're not included by default in an attempt to keep the resulting package as small as possible.默认情况下不包括它们,以试图使生成的 package 尽可能小。

When packaging with AWS SAM, I'm using this in my my_code/requirements.txt , which I then pip install in my local virtual env:使用 AWS SAM 打包时,我在我的my_code/requirements.txt中使用它,然后pip install在我的本地虚拟环境中:

aws-lambda-powertools[parser, validation, tracer]==2.6.0

Additionally, I'm including this in tests/requirements.txt , which I also pip install locally but which is not picked up by SAM (keeping the image small again, and it's not required at runtime anyhow).此外,我将它包含在tests/requirements.txt中,我也在pip install但它没有被 SAM 拾取(再次保持图像较小,并且无论如何在运行时都不需要)。

aws-lambda-powertools[aws-sdk]==2.6.0
pytest==7.2.1

In version 2.0 the xray SDK is not included by default, as this would introduce a size overhead even for those who would not be using Tracer.在 2.0 版中,默认情况下不包含 xray SDK,因为即使对于那些不使用 Tracer 的人来说,这也会带来大小开销。 To solve this problem, just put in your requirements.txt the tracer dependency using aws-lambda-powertools[tracer] or all dependencies using aws-lambda-powertools[all].要解决此问题,只需将使用 aws-lambda-powertools[tracer] 的跟踪器依赖项或使用 aws-lambda-powertools[all] 的所有依赖项放入您的 requirements.txt 中。

Refer This link: https://github.com/awslabs/aws-lambda-powertools-python/issues/1872参考这个链接: https://github.com/awslabs/aws-lambda-powertools-python/issues/1872

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法导入模块“lambda_function”:没有名为“psycopg2._psycopg aws lambda 函数”的模块 - Unable to import module 'lambda_function': No module named 'psycopg2._psycopg aws lambda function AWS Lambda 层无法导入模块“lambda_function”:没有名为“pyarrow.lib”的模块 - AWS Lambda Layer Unable to import module 'lambda_function': No module named 'pyarrow.lib' aws lambda 无法导入模块“lambda_function”:没有名为“requests”的模块 - aws lambda Unable to import module 'lambda_function': No module named 'requests' AWS Lambda 导入错误:无法导入模块“lambda_function”:没有名为“confluent_kafka.cimpl”的模块 - AWS Lambda importError: Unable to import module 'lambda_function': No module named 'confluent_kafka.cimpl 无法导入模块“lambda_function”:没有名为“pymongo”的模块 - Unable to import module 'lambda_function': No module named 'pymongo' AWS Lambda - 无法导入模块“lambda_function” - AWS Lambda - unable to import module 'lambda_function' 无法导入模块“lambda_function”: - Unable to import module 'lambda_function': 无法导入模块“lambda_function”:没有名为“flatten_json”的模块 - Unable to import module 'lambda_function': No module named 'flatten_json' 无法导入模块“lambda_function”:没有名为“orjson.orjson”的模块”, - Unable to import module 'lambda_function': No module named 'orjson.orjson'", AWS Lambda Opencv(“无法导入模块‘lambda_function’:libgthread-2.0.so.0:无法打开共享对象文件:没有这样的文件或目录”) - AWS Lambda Opencv ("Unable to import module 'lambda_function': libgthread-2.0.so.0: cannot open shared object file: No such file or directory")
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM