CloudFormation 坚持认为我的 DynamoDB 创建 JSON 无效,但我看不出问题在哪里。

84

这是由Troposphere生成的JSON(其中包括DynamoDB部分):

"sandbox": {
        "Properties": {
            "AttributeDefinitions": [
                {
                    "AttributeName": "audit_id",
                    "AttributeType": "S"
                },
                {
                    "AttributeName": "status",
                    "AttributeType": "S"
                },
                {
                    "AttributeName": "filename",
                    "AttributeType": "S"
                },
                {
                    "AttributeName": "file_detected_dt",
                    "AttributeType": "S"
                },
                {
                    "AttributeName": "time_taken",
                    "AttributeType": "N"
                },
                {
                    "AttributeName": "number_rows_processed_file",
                    "AttributeType": "N"
                },
                {
                    "AttributeName": "number_rows_created_db",
                    "AttributeType": "N"
                },
                {
                    "AttributeName": "info_messages",
                    "AttributeType": "S"
                }
            ],
            "KeySchema": [
                {
                    "AttributeName": "audit_id",
                    "KeyType": "HASH"
                }
            ],
            "ProvisionedThroughput": {
                "ReadCapacityUnits": {
                    "Ref": "ReadCapacityUnits"
                },
                "WriteCapacityUnits": {
                    "Ref": "WriteCapacityUnits"
                }
            }
        },
        "Type": "AWS::DynamoDB::Table"
    }
CloudFormation 在尝试启动 VPC 时出现错误:Property AttributeDefinitions is inconsistent with the KeySchema of the table and the secondary indexes
但是... 真的吗?我将 audit_id 指定为唯一键,并且它绝对存在于 AttributeDefinitions 列表中。我非常新手 CF(以及 Dynamo),所以我可能会忽略一些极其明显的东西,但目前对我来说并不明显。
我已经在 Google 上搜索了一番,只找到了一个与此错误有关的提及,而这更多地涉及开发人员和 CF 之间的层,而不是 CF 本身。
有人可以指出我的模板有什么问题吗?

CloudFormation Linter规则可帮助更快地捕获此类问题,并提供更多信息:https://github.com/aws-cloudformation/cfn-python-lint/pull/1284 - Pat Myron
1个回答

179

这是由于我对DynamoDB的误解导致的。在这里应该定义仅仅用作键的属性。因此,将AttributeDefinitions数组更改为以下内容解决了问题:

"AttributeDefinitions": [
            {
                "AttributeName": "audit_id",
                "AttributeType": "S"
            }
]

3
这也可以在这里找到:https://dev59.com/ql0Z5IYBdhLWcg3w-EPS#30924384 - Benny Bauer
10
这里的错误在于试图定义表的模式(即关系型数据库中表的“列”)。在DynamoDB中,您仅定义用于检索表中项目值的键,而不是项目本身的模式。DynamoDB是无模式的,存储在每个键下的值是在添加项目时定义的。没有要定义的数据形状。 - Zodman
@Zodman 非常感谢您的评论,特别是这部分内容:“DynamoDb是无模式的,每个键存储的值在添加项目时定义。没有数据形状需要定义。” - Hamed Minaee
3
哦,天啊,我曾经陷在这个问题上很久。谢谢。 - blueprintchris
3
并不是每个英雄都会穿披风……感谢你的注意! - Marcello Grechi Lins
谢谢!我也曾经有过这种误解。 - stef

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接