1

我有 BatchGetItem 的请求映射模板

{
    "version" : "2018-05-29",
    "operation" : "BatchGetItem",
    "tables" : {
        "user-post": { ## Get table name from enviroment varible  or CloudFormation
            "keys": $util.toJson($ids),
            "consistentRead": true
        }
    }
}

和回应$util.toJson($ctx.result.data.user-post)。如何从环境变量或 CloudFormation 中自动获取表名,而不是手动编写它。我的映射模板有数据源user-post- dynamoDB 表。

4

1 回答 1

0

如果您通过 CloudFormation 将解析程序(和映射模板)部署到 AppSync,您应该能够使用引用来自动填充 DynamoDB 表名称。

如果您在同一 cloudformation 模板中创建 DynamoDB 表,则 DynamoDB cloudformation 条目的返回输出将是表名,您可以引用它。

这是使用 cloudformation 创建 DynamoDB 表的文档,返回输出是https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-dynamodb-table.html#w2ab2c21c10d384c15

以下是使用“Ref”来引用资源的文档:https ://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-ref.html

如果您的 DynamoDB 表是预先创建的,您可以通过 cloudformation 堆栈参数或在地图内部传递表名,然后您可以引用它。

您可能必须将“Ref”与其他一些 Cloudformation 帮助函数(例如“Sub”)结合使用,以将 DynamoDB 表引用替换为映射模板定义。

结合使用 Sub 和 Ref 的示例:https ://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-sub.html#w2ab2c21c28c59c11

于 2018-07-26T22:34:44.997 回答