带有Dynamorm的Python中的AWS SAM嵌套应用程序 [英] AWS SAM Nested Application in Python with Dynamorm
问题描述
我正在使用 AWS SAM 来构建无服务器应用程序。我按照说明构建了嵌套应用程序。
I am using AWS SAM to build a Serverless application. I followed the instruction to build a nested application.
我的应用程序结构基本上如下:
My application structure is basically the following:
.
├── 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 / $ c $文件夹中的
requirements.txt
c>具有以下python软件包: boto3
棉花糖
和 dynamorm
。
The requirements.txt
in the folder apps/account/
has the following python packages: boto3
marshmallow
and dynamorm
.
sam构建
和 sam部署
工作正常,并且lambda函数已正确部署。但是,调用lambda函数时收到错误。日志显示以下错误无法导入模块端点:没有名为 dynamorm
的模块。
The sam build
and sam deploy
works fine and the lambda functions are deployed correctly. However, I receive an error when calling the lambda function. The logs show the following error Unable to import module 'endpoints': No module named 'dynamorm'
.
以下是我的代码的摘录:
Here are excerpts from my code:
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()
我不确定我缺少什么?
I am not sure what am I missing? Are there additional instructions to build a nested app in SAM?
非常感谢您的帮助!
推荐答案
根据 https:// github。 com / awslabs / aws-sam-cli / issues / 1213 ,尚不支持此功能。
According to https://github.com/awslabs/aws-sam-cli/issues/1213, this feature is not supported yet.
对于我来说,我做了 sam build在每个嵌套堆栈上并按以下方式修复父yaml模板(使用sam build命令生成的template.yaml),然后可以使用。
In my case, I did 'sam build' on every nested stacks and fix parent yaml template as following (use template.yaml generated by sam build command), then works. But just workaround and not nice way.
XXX_APP:
Type: AWS::Serverless::Application
Properties:
Location: nest_application/.aws-sam/build/template.yaml
这篇关于带有Dynamorm的Python中的AWS SAM嵌套应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!