【发布时间】:2019-02-26 04:30:04
【问题描述】:
我在我的 CloudFormation 模板(用 YAML 编写)中预置了一些 DynamoDB 表资源,我在模板的其他地方预置了一个 AppSync 端点。
我没有指定表的名称,而是让 CloudFormation 为它们生成名称。每当我需要指定表名时,我都会使用
!Ref TableName
我想在 AppSync 中使用 DynamoDB Batch 解析器,这需要我列出表的名称,但是当我更新堆栈时,“!Ref TableName”不会转换为表的名称。解析器以“!Ref TableName”作为表名结束。
有没有办法可以将 CloudFormation 生成的表的名称转换为 AppSync 模板语言?
以下是我的 CloudFormation 模板,已针对相关性进行了修剪:
conversationsTable:
Type: "AWS::DynamoDB::Table"
Properties:
AttributeDefinitions:
-
AttributeName: "id"
AttributeType: "S"
KeySchema:
-
AttributeName: "id"
KeyType: "HASH"
ProvisionedThroughput:
ReadCapacityUnits: "1"
WriteCapacityUnits: "1"
userConversationsTable:
Type: "AWS::DynamoDB::Table"
Properties:
AttributeDefinitions:
-
AttributeName: "userId"
AttributeType: "S"
-
AttributeName: "conversationId"
AttributeType: "S"
KeySchema:
-
AttributeName: "userId"
KeyType: "HASH"
-
AttributeName: "conversationId"
KeyType: "RANGE"
ProvisionedThroughput:
ReadCapacityUnits: "1"
WriteCapacityUnits: "1"
...
createConversationMutationResolver:
Type: "AWS::AppSync::Resolver"
Properties:
ApiId: !GetAtt chatQLApi.ApiId
TypeName: "Mutation"
FieldName: "createConversation"
DataSourceName: !GetAtt conversationsTableDataSource.Name
RequestMappingTemplate: |
{
"version" : "2018-05-29",
"operation" : "BatchPutItem",
"tables": {
!Ref conversationsTable : $util.toJson($convoList),
!Ref userConversationsTable : $util.toJson($users)
}
}
ResponseMappingTemplate: |
#if($context.error)
$util.appendError($context.error.message, $context.error.message)
#end
{
"conversation": $util.toJson("${context.result.data}!Ref conversationTable")
"userConversations": $util.toJson("${context.result.data}!Ref userConversationsTable")
}
【问题讨论】:
标签: amazon-web-services amazon-cloudformation aws-appsync