Python 中使用 Dynamor 的 AWS SAM 嵌套应用程序

AWS SAM Nested Application in Python with Dynamorm

我正在使用 AWS SAM to build a Serverless application. I followed the instruction to build 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 个包:boto3 marshmallowdynamorm

sam buildsam 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 中构建嵌套应用程序的其他说明?

非常感谢您的帮助!

根据https://github.com/awslabs/aws-sam-cli/issues/1213,此功能尚不支持。

在我的例子中,我在每个嵌套堆栈上做了 'sam build' 并按如下方式修复了父 yaml 模板(使用由 sam build 命令生成的 template.yaml),然后工作。但只是解决方法而不是好方法。

  XXX_APP:
    Type: AWS::Serverless::Application
    Properties:
      Location: nest_application/.aws-sam/build/template.yaml