首页 > 解决方案 > 为什么我的 CloudFormation 模板在构建具有单个分区键的简单 DynamoDB 时总是失败?

问题描述

我正在尝试使用 CloudFormation 创建一个简单的 DynamoDB 表。

堆栈本身的创建(甚至没有达到表的创建)总是失败并显示一条Internal Failure. Rollback requested by user消息。

事件选项卡中没有其他信息。奇怪的是,它在创建堆栈时失败,甚至没有尝试创建 DynamoDB 资源。

这适用于具有分区键且没有排序键的简单 DynamoDB 表:

Resources:
  PortalRolesTable:
    Type: AWS::DynamoDB::Table
    Properties:
     TableName: test-env-wb-portal-roles
        AttributeDefinitions:
         - AttributeName: name
           AttributeType: S
        KeySchema:
            - AttributeName: name
              KeyType: HASH

这应该创建表。我有另一个更复杂的模板,它成功构建并创建了一个带有二级索引、排序键和 TTL 等的堆栈。我不知道为什么我对此没有任何运气。

标签: amazon-dynamodbamazon-cloudformation

解决方案


我刚刚使用了 AWS - Chrome Web Store 的精彩控制台记录器来生成模板并得到:

AWSTemplateFormatVersion: "2010-09-09"
Resources:
    dynamodb1a42db5:
        Type: "AWS::DynamoDB::Table"
        Properties:
            TableName: "test-env-wb-portal-roles"
            BillingMode: "PROVISIONED"
            KeySchema: 
              - 
                AttributeName: "name"
                KeyType: "HASH"
            ProvisionedThroughput: 
                ReadCapacityUnits: 5
                WriteCapacityUnits: 5
            SSESpecification: 
                Enabled: false

这似乎KeySchema是一个字典列表,需要将破折号与字典值分开。

请参阅以下 YAML 代码示例:AWS::DynamoDB::Table - AWS CloudFormation


推荐阅读