-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not try to delete lambda@edge functions with replicas #1721
Comments
I'm having this problem also. |
I can't reproduce a crash in Terraform v0.10.7, but I do still hit a dead-end where Terraform is unable to delete the resource:
It would be useful for the |
You can delete a CF trigger, but apparently there is actually no way to delete replicated functions Consequence: You can no longer delete the original function that was used as a CF trigger 😞 https://forums.aws.amazon.com/thread.jspa?threadID=260242&tstart=0
|
@ctd I believe the "crash" @rarguelloF describes is likely the error that is thrown. The error effectively prevents you from altering the Lambda function (e.g. renaming, deleting), as Terraform aborts any changes when failing to delete the original, replicated function. For my project, I had to destroy and recreate the |
Support reply regarding this on Nov 27, 2017
Any one have an idea what |
If a Lambda@Edge can be used for other behaviors and/or other CloudFront distributions, it makes sense to me to put in it's own terrform project, and just refer to it, so that destroying a distribution or removing a Lambda trigger from a behavior shouldn't attempt to destroy the (reusable) Lambda function. Other than using |
Same problem here.. |
-_- ... sometimes aws is killing me ;) |
January 12, 2018. I just did my level best to find a way, any way, to delete a function that has been replicated. I'm guessing that someone inside of AWS closed the bug report not understanding how serious this issue is. |
I am also blocked by this issue unfortunately. We are trying to implement automated tests using the kitchen terraform plugin and aws-spec and this issue completely blocks this due to the terraform destroy erroring if you have a lambda@edge function in your stack. My first thought for getting around this issue was to remove the lambda@edge functionality from the module only when tests are run but I have been unable to figure out how to accomplish this. It seems impossible to do this since the Is there some other way that I can conditionally set that property based on a variable value to selectively enable or disable those associations? Since the lambda replicas will be deleted by cloudfront with eventual consistency once the associations to the cloudfront distro has been deleted is it enough to delete the associations on destroy and trust cloudfront will eventually get them cleaned up or is the aws api erroring deleting the main lambda function due to the fact that replicas exist? Either way, until AWS fixes their issue, which seems like they aren't going to be doing anytime soon, is it possible to have the deletion be treated as a warning so it doesn't just completely block anyone trying to use it now? Even if we get a warning and have to clean up the function manually at a later date that seems the best we can hope for until AWS addresses this properly. Thanks! |
For the sake of posterity, based on the Deleting Lambda@Edge Functions and Replicas documentation stating replicas are "deleted within a few hours" I was able to...
So, if your use-case doesn't require everything occurring in a single Terraform apply, you should be able to delete/rename Lambda functions if you wait long enough for the replicas to be deleted after all associations to the Lambda are removed. Annoying and limiting, but worked in my simple case. |
Terraform v0.11.7 - Throws error but actually applies all the other changes for me. TL;DRYou can also remove it from CF via the console then wait 30 minutes. You don't have to do it via TF per say. BUT..... While that works, I don't see how I can use this approach for a production environment given that the Lambda@Edge function serves live traffic rules. If I remove it for an hour I'm creating a production system outage for an hour. Which means that if you use Lambda@Edge and you need to make a change your SOL and have to take an outage. FYI - Amazon has the same problem with Cloud Formation templates as well. |
Also, CloudFront takes 15ish minutes to deploy a change, so every part of this sucks. You could consider fixing this with an A and a B distribution which sit behind an edge distribution via a cache behavior, update the inactive one, then change the edge to point at the inactive one. But that will take 15 minutes to deploy, during which you can't reliably know if A or B is being used. So if you needed to quickly iterate, forget about it. |
@dmitrye for your production use case, you could likely do the following to avoid service interruptions...
|
@dcalhoun Yes, that would avoid an outage. But then I have to remember to clean up old lambda@edge. Unused lambda's don't cost me, so theoretically you could have a weekly script/job via TF that cleans up old functions from your config. Would be nice if TF incremented the definition name with an ID (or some other tokenizer) so that each compile generates a new function instead of updating existing one. |
i too also hit the same problem today :( |
Yep. This is an issue. The |
Is there a way to ignore only this Error and make the stack destroy pass ? |
Is it possible to realize the expectation of removal of replicas, for example, through a timeout function, so that the terraform itself checks the fact of deleting replicas and then hangs without error? |
I also ran into this issue when trying to rename a lambda@edge function (essentially replacing an existing function with a new one). The Cloudfront update would fail as terraform is unable to delete the lambda function immediately. My workaround was to delete the function from state first:
And then run |
3 years later and this is still a problem ... really, the fix needs to come from Amazon. If they didn't treat trying to delete a replicated function as an error, this all goes away. I put up a forum thread, please check it out if you agree https://forums.aws.amazon.com/thread.jspa?threadID=331402 |
I have workaround for this issue, this helped me to overcome this known issue resource "time_sleep" "wait_30_seconds" { destroy_duration = "1200s" resource "null_resource" "next" { |
thanks a lot, looks like it works |
Hi, when you do "terraform destroy" terraform destroy the cloud front first and lambda. sample code helps you to delete the lambda function after 1200 seconds. |
@dcalhoun Can you tell me how to remove the association? What does that look like? |
@josh803316 it has been almost 4 years since I posted this, so I struggle to recall the specific steps. 😅 I imagine it involves removing the diff --git a/example.yml b/example.yml
index 4b843c1..929c01f 100644
--- a/example.yml
+++ b/example.yml
@@ -4,11 +4,5 @@ resource "aws_cloudfront_distribution" "example" {
# lambda_function_association is also supported by default_cache_behavior
ordered_cache_behavior {
# ... other configuration ...
-
- lambda_function_association {
- event_type = "viewer-request"
- lambda_arn = aws_lambda_function.example.qualified_arn
- include_body = false
- }
}
} Hope this helps! |
@dcalhoun Yes it does and it's the same thing I arrived at as well. The good news is that it does allow me to destroy all the resources except the lambda function, the bad news is the destroy still ends up failing because of the issue above (replication and lambdas not being destroyed immediately). Thanks so much for the suggestion! |
Based on the age of this issue, I would say that at this point it needs to be thoroughly researched again to ensure it is still an issue. There may be an upstream component to this but in the provider we may be able to do something to improve the behavior (e.g., eating the error or trying eventual consistency approaches to wait for CF). |
It's still indeed an issue. The workaround above — #1721 (comment) — works, however we should look into adding native support for this in the provider itself. |
To add another data point - this is still an issue in Jan 2023. |
I confirm this is still an issue for us. |
It is still an issue for us as well. |
The proposed solution for this issue is to add a
and others. If the attribute is set to |
Build on #29615. |
That doesn’t resolve the issue though. It merely makes it so the user now has to manually delete the lambda. The workaround with the sleep and null resource are an appropriate method to maintain automated resources. |
@ewbankkit I would like to pick up your solution as a PR if no one else is working on it |
@richardjennings I'll be doing the PR, likely submitted later today. Thanks though 👏. |
@edwardofclt I also plan on retrying delete (up to a configurable timeout) if the error code indicates a replicated Lambda@Edge function. |
This functionality has been released in v4.57.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
Terraform fails to delete lambda@edge functions that were already replicated, as AWS just doesn't let it.
From http://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html:
Terraform Version
Terraform v0.10.6
Affected Resource(s)
Expected Behavior
Terraform should not fail and should give you some kind of warning that it couldn't delete the resource because AWS just doesn't let you.
Actual Behavior
Terraform fails as it's trying to delete lambda function and AWS doesn't allow it.
Steps to Reproduce
terraform apply
The text was updated successfully, but these errors were encountered: