【发布时间】:2021-01-07 06:25:45
【问题描述】:
我有一个基于 python 3.7 的 AWS Lambda 函数,并尝试通过 AWS 层使用模块 dicttoxml。我的 Python 代码如下:
import json
import dicttoxml
def lambda_handler(event, context):
xml = dicttoxml.dicttoxml({"name": "Foo"})
return {
'statusCode': 200,
'body': json.dumps('Hello from Lambda!')
}
在我的本地机器上,它工作得很好,但 Lambda 给出如下错误:
{
"errorMessage": "module 'dicttoxml' has no attribute 'dicttoxml'",
"errorType": "AttributeError",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 4, in lambda_handler\n xml = dicttoxml.dicttoxml({\"name\": \"Ankur\"})\n"
]
}
dicttoxml层的directory structure如下:
dicttoxml.zip > python > dicttoxml > dicttoxml.py
我很疑惑,这里有什么问题?
【问题讨论】:
-
你是如何创建图层的?似乎格式不正确。
-
是的,我创建了图层并附加到函数
-
我提供了如何正确创建这样一个图层的步骤。如果您发现答案有帮助,我们将不胜感激。另外,如果您有任何问题,请随时提出。
标签: python-3.x amazon-web-services aws-lambda aws-lambda-layers