如何解决AWS CloudFormation 堆栈创建不断失败
我正在尝试使用 CloudFormation 堆栈创建 DynamoDB 表,但是我一直在 AWS 控制台中收到“CREATE_Failed”错误,我不确定我哪里出错了。
我的 create_stack 方法:
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",{
"AttributeName":"Negative score",{
"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] 描述表和索引的关键架构的属性列表。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。