[英]AWS CloudFormation Stack Creation Keeps Failing
我正在尝试使用 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"
}
}
}
}
我的控制台打印了创建的堆栈,但控制台中没有明确指示为什么它一直失败。
查看您的堆栈的“事件”选项卡。 它将向您显示详细的操作并解释首先失败的步骤。 具体会告诉你:
一个或多个参数值无效:KeySchema 中的属性数与 AttributeDefinitions 中定义的属性数不完全匹配(服务:AmazonDynamoDBv2;状态代码:400;错误代码:ValidationException;请求 ID:12345;代理:null)
问题是您已经为所有表属性提供了定义。 您应该只提供关键属性。
根据AttributeDefinitions文档:
[AttributeDefinitions is] 描述表和索引的键模式的属性列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.