当使用AWS CloudFormation创建资源时,可能会遇到资源创建失败的错误。以下是一些常见的错误和解决方法,包括代码示例:
"The provided execution role does not have permissions to call the service IAM"(提供的执行角色没有调用IAM服务的权限):
iam:CreateRole
权限。Resources:
MyExecutionRole:
Type: "AWS::IAM::Role"
Properties:
RoleName: MyExecutionRole
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "cloudformation.amazonaws.com"
Action:
- "sts:AssumeRole"
Policies:
- PolicyName: MyExecutionRolePolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action: "iam:CreateRole"
Resource: "*"
"The security group 'sg-xxxxxxxx' does not exist"(安全组 'sg-xxxxxxxx' 不存在):
Resources:
MySecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupName: MySecurityGroup
VpcId: vpc-xxxxxxxx
# 添加其他属性
"No EC2 subnets found in VPC ID 'vpc-xxxxxxxx'"(在VPC ID 'vpc-xxxxxxxx' 中找不到EC2子网):
Resources:
MySubnet:
Type: "AWS::EC2::Subnet"
Properties:
VpcId: vpc-xxxxxxxx
CidrBlock: 10.0.0.0/24
# 添加其他属性
这些是常见的AWS CloudFormation资源创建失败的错误和解决方法。根据错误信息和具体情况,可以采取相应的措施来解决问题。