Skip to content

How do I resolve the "NetworkInterfaces associated with the Lambda function to be cleaned up" message when I delete an CloudFormation stack?

3 minute read
0

I tried to delete an AWS CloudFormation stack. I received the "CloudFormation is waiting for NetworkInterfaces associated with the Lambda function to be cleaned up" message.

Short description

Requester-managed network interfaces are elastic network interfaces that AWS services such as AWS Lambda create in your Amazon Virtual Private Cloud (Amazon VPC). For more information, see Requester-managed network interfaces.

Lambda creates and deletes the network interfaces for your functions. You can't delete a network interface when it's in use.

When you delete the stack, CloudFormation waits for Lambda to delete the network interfaces before CloudFormation deletes the security group and subnets. If another function or function version uses the network interface, then Lambda doesn't delete it. Lambda also can't delete the network interface if the function's execution role or its Amazon Elastic Compute Cloud (Amazon EC2) permissions are removed first. The stack deletion then fails after about 45 minutes with a "has a dependent object" error.

For more information, see Understanding Hyperplane Elastic Network Interfaces (ENIs).

Resolution

Lambda network interfaces

To reduce the time that it takes to delete network interfaces with CloudFormation stacks, complete the following steps:

  1. Make sure that other Lambda functions, function versions, or event source mappings don't use the network interface. If the network interface is associated with a Lambda function version, then delete the function versions. You can't edit a published Lambda function version, and you can't change its Amazon VPC configuration. To find and delete the network interface, follow the steps to run the Lambda elastic network interface finder.

  2. Before you delete the CloudFormation stack, change the Amazon VPC configuration to None. Make this change for each Lambda function that shares the same security group and subnet combination. Lambda deletes the network interface up to 20 minutes after no function or function version uses it.

    Note: Keep the function's execution role and its Amazon EC2 permissions until Lambda deletes the network interface. If the role is already deleted and no function uses the network interface, then delete the network interface manually and delete the stack again.

Amazon Bedrock network interfaces

Amazon Bedrock AgentCore Runtime network interfaces have the agentic AI interface type and cause the same "has a dependent object" error. CloudFormation doesn't wait for these network interfaces, and you can't delete them. AgentCore removes the network interfaces up to 8 hours after you delete the agent runtime. After AgentCore removes the network interfaces, delete the stack again. For more information, see Configure Amazon Bedrock AgentCore Runtime and tools for VPC.

Related information

Why can't I detach or delete an elastic network interface that Lambda created?

Giving Lambda Event Functions access to resources in an Amazon VPC

AWS OFFICIALUpdated 6 days ago