Cloudformation slow to delete lambda

0

I'm using cdk to deploy lambda functions and there supporting infra inside my vpc. Typically a deployment takes a couple of minutes. However sometimes Cloudformation is painfully slow. I am currently waiting over 25 mins for a lambda version to be deleted.

Enter image description here

2 Answers
3

Hello,

You are right 😕 Lambdas within a VPC can take time to be destroyed by CDK. Here are some docs explaining why and some workarounds:

Hope this helps! 😊

profile pictureAWS
answered 2 months ago
0

The slow deletion of Lambda functions in CloudFormation, especially when they are connected to a VPC, is a known issue that can occur due to the way AWS manages network interfaces associated with Lambda functions.

When you delete a Lambda function that is connected to a VPC, CloudFormation needs to wait for AWS Lambda to delete the associated network interfaces before it can proceed with deleting other resources. This process can sometimes take a considerable amount of time, leading to the slow deletion you're experiencing.

To address this issue, you can try the following:

  1. Ensure that your CloudFormation stack has the necessary permissions to monitor and delete network interfaces. Specifically, the ec2:DescribeNetworkInterfaces permission is required for CloudFormation to monitor the state of network interfaces.

  2. If your stack is in a DELETE_FAILED state due to issues with deleting certain resources (like non-empty S3 buckets), you can use the new DeletionMode parameter with the FORCE_DELETE_STACK value for the DeleteStack API. This allows you to forcefully delete stacks that are in a DELETE_FAILED state.

  3. For Lambda@Edge functions, make sure to remove all associations with CloudFront distributions before attempting to delete the function. After removing associations, wait a few hours for the Lambda@Edge function replicas to be cleaned up automatically before deleting the function.

  4. If you're frequently creating and deleting Lambda functions for testing purposes, consider using a separate stack for your Lambda functions or implementing a strategy to manage function versions more efficiently.

  5. If the issue persists, you may want to reach out to AWS support for further assistance, as there might be underlying issues specific to your account or region.

Remember that while these steps can help mitigate the issue, some delay in deleting Lambda functions connected to VPCs is expected due to the necessary cleanup of network resources.
Sources
AWS::Lambda::Function VpcConfig - AWS CloudFormation
AWS CloudFormation accelerates dev-test cycle with a new parameter for DeleteStack API - AWS
Delete Lambda@Edge functions and replicas - Amazon CloudFront
DeleteFunction - AWS Lambda

profile picture
answered 2 months ago
  • Total time: 2507.59s

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions