public async Task detachAndDeleteInternetGatewaysAsync(string vpcid)
{
var request = new DescribeInternetGatewaysRequest();
var filter = new Filter { Name = "attachment.vpc-id" };
filter.Values.Add(vpcid);
request.Filters.Add(filter);
var response = await _ec2Client.DescribeInternetGatewaysAsync(request);
foreach (var gateway in response.InternetGateways)
{
await _ec2Client.DetachInternetGatewayAsync(new DetachInternetGatewayRequest {
InternetGatewayId = gateway.InternetGatewayId, VpcId = vpcid
});
await _ec2Client.DeleteInternetGatewayAsync(new DeleteInternetGatewayRequest {
InternetGatewayId = gateway.InternetGatewayId
});
}
}