gpt4 book ai didi

amazon-web-services - 无法删除通过 CloudFormation 模板附加到 EC2 实例的其他 ENI

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

我使用以下模板来配置资源:

      Resources:
PrimaryADC:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: "{{ ami_id }}"
InstanceType: "{{ instance_type }}"
NetworkInterfaces:
- AssociatePublicIpAddress: true
DeleteOnTermination: true
Description: "Mgmt interface"
SubnetId: "{{ mgmt_subnet_id }}"
DeviceIndex: 0

PrimaryADCClientNic:
Type: 'AWS::EC2::NetworkInterface'
Properties:
Description: "Client interface"
SubnetId: "{{ client_subnet_id }}"
DependsOn: PrimaryADC
PrimaryADCServerNic:
Type: 'AWS::EC2::NetworkInterface'
Properties:
Description: "Server interface"
SubnetId: "{{ server_subnet_id }}"
DependsOn: PrimaryADC
ClinetNetworkInterfaceAttachment:
Type: AWS::EC2::NetworkInterfaceAttachment
Properties:
DeleteOnTermination: true
InstanceId:
Ref: PrimaryADC
NetworkInterfaceId:
Ref: PrimaryADCClientNic
DeviceIndex: 1
ServerNetworkInterfaceAttachment:
Type: AWS::EC2::NetworkInterfaceAttachment
Properties:
DeleteOnTermination: true
InstanceId:
Ref: PrimaryADC
NetworkInterfaceId:
Ref: PrimaryADCServerNic
DeviceIndex: 2
Outputs:
instanceid:
Value:
Ref: PrimaryADC

当我删除堆栈时,它总是尝试先删除额外的两个网络接口(interface)。这会引发错误,因为它们仍会附加到实例。我尝试为接口(interface)提供 DependsOn ,但这不起作用。在尝试删除任何附加的网络接口(interface)(客户端和服务器)之前,如何确保实例已被删除。

我正在使用 boto3 创建堆栈。并通过GUI删除。

来自堆栈部署的 json 文件:

{
"Resources":{
"PrimaryADC":{
"Properties":{
"InstanceType":"c5.xlarge",
"NetworkInterfaces":[
{
"AssociatePublicIpAddress":True,
"SubnetId":"**********",
"Description":"Mgmt interface",
"DeviceIndex":0,
"DeleteOnTermination":True
}
],
"ImageId":"*************"
},
"Type":"AWS::EC2::Instance"
},
"PrimaryADCServerNic":{
"Properties":{
"SubnetId":"******************",
"Description":"Server interface"
},
"Type":"AWS::EC2::NetworkInterface",
"DependsOn":"PrimaryADC"
},
"ServerNetworkInterfaceAttachment":{
"Properties":{
"InstanceId":{
"Ref":"PrimaryADC"
},
"NetworkInterfaceId":{
"Ref":"PrimaryADCServerNic"
},
"DeviceIndex":2,
"DeleteOnTermination":True
},
"Type":"AWS::EC2::NetworkInterfaceAttachment"
},
"ClinetNetworkInterfaceAttachment":{
"Properties":{
"InstanceId":{
"Ref":"PrimaryADC"
},
"NetworkInterfaceId":{
"Ref":"PrimaryADCClientNic"
},
"DeviceIndex":1,
"DeleteOnTermination":True
},
"Type":"AWS::EC2::NetworkInterfaceAttachment"
},
"PrimaryADCClientNic":{
"Properties":{
"SubnetId":"*************",
"Description":"Client interface"
},
"Type":"AWS::EC2::NetworkInterface",
"DependsOn":"PrimaryADC"
}
},
"Outputs":{
"instanceid":{
"Value":{
"Ref":"PrimaryADC"
}
}
}
}

最佳答案

尝试重现该问题,但在我的测试中一切都按预期工作。这是我使用的模板,因为您的模板不完整:

Parameters:

amiid:
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'

mgmtsubnetid:
Type: AWS::EC2::Subnet::Id

clientsubnetid:
Type: AWS::EC2::Subnet::Id

serversubnetid:
Type: AWS::EC2::Subnet::Id

Resources:

PrimaryADC:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: !Ref amiid
InstanceType: t3.medium
NetworkInterfaces:
- AssociatePublicIpAddress: true
DeleteOnTermination: true
Description: "Mgmt interface"
SubnetId: !Ref mgmtsubnetid
DeviceIndex: 0

PrimaryADCClientNic:
Type: 'AWS::EC2::NetworkInterface'
Properties:
Description: "Client interface"
SubnetId: !Ref clientsubnetid
DependsOn: PrimaryADC

PrimaryADCServerNic:
Type: 'AWS::EC2::NetworkInterface'
Properties:
Description: "Server interface"
SubnetId: !Ref serversubnetid
DependsOn: PrimaryADC

ClinetNetworkInterfaceAttachment:
Type: AWS::EC2::NetworkInterfaceAttachment
Properties:
DeleteOnTermination: true
InstanceId:
Ref: PrimaryADC
NetworkInterfaceId:
Ref: PrimaryADCClientNic
DeviceIndex: 1

ServerNetworkInterfaceAttachment:
Type: AWS::EC2::NetworkInterfaceAttachment
Properties:
DeleteOnTermination: true
InstanceId:
Ref: PrimaryADC
NetworkInterfaceId:
Ref: PrimaryADCServerNic
DeviceIndex: 2
Outputs:
instanceid:
Value:
Ref: PrimaryADC

关于amazon-web-services - 无法删除通过 CloudFormation 模板附加到 EC2 实例的其他 ENI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64261267/

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