【问题标题】:AWS SAM Nested Application in Python with Dynamorm使用 Dynamorm 的 Python 中的 AWS SAM 嵌套应用程序
【发布时间】: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包:boto3marshmallowdynamorm

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

非常感谢您的帮助!

【问题讨论】:

    标签: python-3.x amazon-web-services amazon-dynamodb aws-serverless aws-sam


    【解决方案1】:

    根据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
    

    【讨论】:

    • 谢谢本尼。有效。不过,我同意这应该得到支持。
    猜你喜欢
    • 2021-09-27
    • 2020-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-18
    • 2019-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多