Skip to content

Instantly share code, notes, and snippets.

@tecmaverick
Created August 30, 2018 00:55
Show Gist options
  • Save tecmaverick/26e015f4b104ae4a1de72b1d53e54d82 to your computer and use it in GitHub Desktop.
Save tecmaverick/26e015f4b104ae4a1de72b1d53e54d82 to your computer and use it in GitHub Desktop.
View and delete ENIs created by lambda in "available" status
#Specify the region you want to run your scripts
region_val="ap-southeast-2"
#View Lambda function name asscoiated with ENIs in *in-use* status in a specific AWS region
aws ec2 describe-network-interfaces \
--filters "Name=description,Values='AWS Lambda VPC ENI*'" "Name=status,Values='in-use'" \
--query "NetworkInterfaces[].[RequesterId,Status,NetworkInterfaceId]" \
--output text --region $region_val
#View Lambda function name asscoiated with ENIs in *available* status in a specific AWS region
aws ec2 describe-network-interfaces \
--filters "Name=description,Values='AWS Lambda VPC ENI*'" "Name=status,Values='available'" \
--query "NetworkInterfaces[].[RequesterId,Status,NetworkInterfaceId]" \
--output text --region $region_val
#Deletes ENIs in *available* status created by lambda function(s) in the specific AWS region
aws ec2 describe-network-interfaces \
--filters "Name=description,Values='AWS Lambda VPC ENI*'" "Name=status,Values='available'" \
--query "NetworkInterfaces[].[NetworkInterfaceId]" \
--output text \
--region $region_val | \
xargs -I {} \
aws ec2 delete-network-interface \
--network-interface-id {} \
--region $region_val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment