gpt4 book ai didi

amazon-web-services - ec2 实例缺少 Cloudformation DeletionPolicy 策略

转载 作者:行者123 更新时间:2023-12-03 07:11:59 26 4
gpt4 key购买 nike

我正在尝试创建一个堆栈(请参阅下面的代码)

但我收到以下错误:

There was an error creating this change set.
The following resources to import [masterinstance] must have DeletionPolicy attribute specified in the template.

我不知道如何解决这个问题。我尝试在 InstanceType 定义下添加"DeletionPolicy": "Retain",但这不正确。

"InstanceType": {

"Description": "EC2 instance type for the node instances",

"Type": "String",
"Default": "t3.micro",
"DeletionPolicy": "Retain",

有人可以解释一下我做错了什么以及如何更改模板吗?

非常感谢。

模板:

{

"AWSTemplateFormatVersion" : "2010-09-09",

"Description" : "Template to create a RHEL8 instances for testings",

"Parameters": {

"instanceName": {

"Description": "The instance name.",

"Type": "String"

},

"Subnet": {

"Description": "The subnets where the instance is created.",

"Type": "AWS::EC2::Subnet::Id"

},

"securitygroup": {

"Description": "The subnets where workers can be created.",

"Type": "List<AWS::EC2::SecurityGroup::Id>"

},

"InstanceType": {

"Description": "EC2 instance type for the node instances",

"Type": "String",
"Default": "t3.micro",
"AllowedValues": [

"t3.micro", "t3.small", "t2.medium"

],

"ConstraintDescription": "Must be a valid EC2 instance type"

},

"KeyName": {

"Description": "The EC2 Key Pair to allow SSH access to the instances",

"Type": "AWS::EC2::KeyPair::KeyName"

},

"volumeSize": {

"Description": "Size of EBS volume in GB",

"Type": "Number"

},

"ami" : {

"Description": "ami of instance",

"Type" : "AWS::EC2::Image::Id",

}
},

"Resources" : {

"masterinstance" : {

"Type" : "AWS::EC2::Instance",

"Properties" : {

"BlockDeviceMappings" : [ {

"DeviceName" : "/dev/sda1",

"Ebs" : {

"DeleteOnTermination" : "False",

"Encrypted" : "False",

"VolumeSize" : {"Ref": "volumeSize"},

"VolumeType" : "gp2"

}

}],

"ImageId" : {"Ref": "ami"},

"InstanceType" : {"Ref" : "InstanceType"},

"KeyName" : {"Ref": "KeyName"},

"SecurityGroupIds" : {"Ref" : "securitygroup"},

"SubnetId" : {"Ref": "Subnet"},

"Tags" : [ {

"Key" : "Name",

"Value" : {"Ref": "instanceName"}

} ]

}

}

}

}

最佳答案

DeletionPolicy应放置在您的实际实例资源中,而不是输入参数中。例如:

"MyEC2Instance" : {
"Type" : "AWS::EC2::Instance",
"DeletionPolicy" : "Retain",
"Properties" : {
"ImageId" : "ami-79fd7eee",
"KeyName" : "testkey",
...

关于amazon-web-services - ec2 实例缺少 Cloudformation DeletionPolicy 策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70778233/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com