【发布时间】:2020-02-12 10:10:09
【问题描述】:
我正在使用AWS SAM 构建无服务器应用程序。我按照说明构建a nested application。
我的应用结构基本如下:
.
├── MAKEFILE
├── README.md
├── __init__.py
├── apps
│ ├── __init__.py
│ ├── account
│ │ ├── __init__.py
│ │ ├── endpoints.py
│ │ ├── models.py
│ │ ├── requirements.txt
│ │ └── template.yaml
├── samconfig.toml
└── template.yaml
文件夹apps/account/中的requirements.txt有以下python包:boto3marshmallow和dynamorm。
sam build 和 sam deploy 工作正常,并且 lambda 函数已正确部署。但是,调用 lambda 函数时收到错误消息。日志显示以下错误Unable to import module 'endpoints': No module named 'dynamorm'。
以下是我的代码节选:
endpoints.py
import json
import boto3
from models import Account
print('Loading function')
def account_info(event, context):
apiKey = event["requestContext"]["identity"]["apiKeyId"]
account_info = Account.get(id= apiKey)
return {
"statusCode": 200,
"body": json.dumps(account_info)
}
models.py
import datetime
from dynamorm import DynaModel, GlobalIndex, ProjectAll
from marshmallow import Schema, fields, validate, validates, ValidationError
class Account(DynaModel):
# Define our DynamoDB properties
class Table:
name = 'XXXXXXXXXX'
hash_key = 'id'
read = 10
write = 5
class Schema:
id = fields.String(required=True)
name = fields.String()
email = fields.String()
phonenumber = fields.String()
status = fields.String()
我不确定我错过了什么?是否有在 SAM 中构建嵌套应用程序的其他说明?
非常感谢您的帮助!
【问题讨论】:
标签: python-3.x amazon-web-services amazon-dynamodb aws-serverless aws-sam