Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudFormation is waiting for NetworkInterfaces associated with the Lambda Function to be cleaned up

I have a CloudFormation stack with Lambda function inside a VPC,
When trying to delete the stack, the AWS CloudFormation gets stuck for 25-30 at least,
I get the following message in the events -

CloudFormation is waiting for NetworkInterfaces associated with the Lambda Function to be cleaned up.

It seems to be due to ENIs being attached to the Functions and the SecurityGroups.

From the Console it did not allow me to delete either the ENI forcibly nor the Security Group, to which the ENI is attached,
So do I just have to wait?

I found some questions and blogs which are even 2 years old,
No solution from AWS?
Automations are supposed to be quick, this is proving to be a huge blocker.

Reference -
CloudFormation issue: couldn't delete stack
https://forum.serverless.com/t/very-long-delay-when-doing-sls-remove-of-lambda-in-a-vpc/2535

like image 395
Ani Avatar asked Oct 31 '19 10:10

Ani


People also ask

How long does it take to delete a lambda function?

AWS CloudFormation uses elastic network interfaces, and elastic network interfaces can only be deleted by Lambda. Deleting an elastic network interface can take up to 45 minutes.

Can CloudFormation interact with Lambda?

All in all, CloudFormation makes deploying AWS Lambda functions incredibly simple. Start by creating the template file that will define your resources. This will be your working folder for your code. Next, create your function in the appropriate file for your desired Lambda runtime.


1 Answers

As you and others have already mentioned, this is a known issue/"feature". When I last spoke about this with someone from AWS, there were no plans of changing this behavior. If time is really of the essence for you, one work-around you can try is this:

  1. Update the Lambda resources in CloudFormation with DeletionPolicy set to Retain.

  2. Manually (or via script/API) delete the Lambda and associated resources like ENIs

However, I would not recommend against the above mentioned work-around. It is easy to forget something which will leave you with a cluttered environment.

like image 184
Rob Avatar answered Oct 16 '22 21:10

Rob