Automate deletion of orphaned network interfaces.

0

A customer has thousands of network interfaces in the us-east-1. The customer is looking for a way to identify any network interfaces that have not been used in the last 90 days and delete them all.

Customer is aware he can use the AWS CLI to identify instances that are not in-use and delete them by providing the id for each interface.

My Question:

Is there a way to automate this entire process? Finding all the network interfaces older than 90 days and deleting them?

If there is no way to identify when they were last used, is there a way for the customer delete all the network interfaces that are not in use and delete all of them at once.

AWS
已提问 5 年前533 查看次数
1 回答
0
已接受的回答

When you try to delete an ENI, if the interface is in use, you'll be prevented from doing so. You can see ahead of time which ENIs are in use in the VPC console, under Network Interfaces.

Programatically, as I see it, you have two choices (or a combination of both). Firstly, if you don't care when an interface was last used so long as it isn't currently being used, then you can parse the output of aws ec2 describe-network-interfaces; the status section of the response is available (if not in use) and in-use (if, well, in use). If you do care, you could take each of these ENI IDs and parse through your VPC Flow Logs to find any traffic over that interface in the last X period, and use that to determine whether or not you delete the interface.

However, remember that VPC Flow Logs will log any traffic received by an ENI - if someone tries to connect to a port on an IP served by an ENI from the outside, that will show as activity. If you want to filter just so that you only look for customer-initiated activity to that ENI, then VPC Flow Logs can help, but you'd need to parse a little more to work out the source IP address.

AWS
专家
已回答 5 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则