【问题标题】:AWS CloudFormation Stack Creation Keeps FailingAWS CloudFormation 堆栈创建不断失败
【发布时间】:2021-06-29 13:18:22
【问题描述】:

我正在尝试使用 CloudFormation 堆栈创建一个 DynamoDB 表,但是我一直在 AWS 控制台中收到“CREATE_FAILED”错误,我不确定我哪里出错了。

我创建堆栈的方法:

cf = boto3.client('cloudformation')
stack_name = 'teststack'

with open('dynamoDBTemplate.json') as json_file:
    template = json.load(json_file)
    template = str(template)

try:
    response = cf.create_stack(
        StackName = stack_name,
        TemplateBody = template,
        TimeoutInMinutes = 123,
        ResourceTypes = [
            'AWS::DynamoDB::Table',
        ],
        OnFailure = 'DO_NOTHING',
        EnableTerminationProtection = True
    )
    print(response)
except ClientError as e:
    print(e)

这是我的 JSON 文件:

{
   "AWSTemplateFormatVersion":"2010-09-09",
   "Resources":{
      "myDynamoDBTable":{
         "Type":"AWS::DynamoDB::Table",
         "Properties":{
            "AttributeDefinitions":[
               {
                  "AttributeName":"Filename",
                  "AttributeType":"S"
               },
               {
                  "AttributeName":"Positive Score",
                  "AttributeType":"S"
               },
               {
                  "AttributeName":"Negative Score",
                  "AttributeType":"S"
               },
               {
                  "AttributeName":"Mixed Score",
                  "AttributeType":"S"
               }
            ],
            "KeySchema":[
               {
                  "AttributeName":"Filename",
                  "KeyType":"HASH"
               }
            ],
            "ProvisionedThroughput":{
               "ReadCapacityUnits":"5",
               "WriteCapacityUnits":"5"
            },
            "TableName":"testtable"
         }
      }
   }
}

我的控制台打印了创建的堆栈,但控制台中没有明确指示为什么它一直失败。

【问题讨论】:

    标签: python amazon-web-services amazon-dynamodb amazon-cloudformation


    【解决方案1】:

    查看您的堆栈的“事件”选项卡。它将向您显示详细的操作并解释首先失败的步骤。具体会告诉你:

    一个或多个参数值无效:KeySchema 中的属性数与 AttributeDefinitions 中定义的属性数不完全匹配(服务:AmazonDynamoDBv2;状态代码:400;错误代码:ValidationException;请求 ID:12345;代理:null)

    问题在于您已经为所有表属性提供了定义。您应该只提供关键属性。

    根据AttributeDefinitions 文档:

    [AttributeDefinitions is] 描述表和索引的键模式的属性列表。

    【讨论】:

      猜你喜欢
      • 2017-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-05
      • 1970-01-01
      • 2012-12-02
      • 2018-10-01
      • 2020-10-23
      相关资源
      最近更新 更多