我在用AWS SAM https://aws.amazon.com/serverless/sam/构建无服务器应用程序。我按照说明构建嵌套应用程序 https://aws.amazon.com/blogs/compute/announcing-nested-applications-for-aws-sam-and-the-aws-serverless-application-repository/.
我的应用程序结构基本上如下:
.
├── MAKEFILE
├── README.md
├── __init__.py
├── apps
│ ├── __init__.py
│ ├── account
│ │ ├── __init__.py
│ │ ├── endpoints.py
│ │ ├── models.py
│ │ ├── requirements.txt
│ │ └── template.yaml
├── samconfig.toml
└── template.yaml
The requirements.txt
在文件夹中apps/account/
有以下 python 包:boto3
marshmallow
and dynamorm
.
The sam build
and sam deploy
工作正常并且 lambda 函数部署正确。但是,我在调用 lambda 函数时收到错误。日志显示以下错误Unable to import module 'endpoints': No module named 'dynamorm'
.
以下是我的代码的摘录:
端点.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)
}
模型.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 中构建嵌套应用程序的附加说明?
十分感谢你的帮助!