Remove does not clean all resources
It seems that remove does not keep all resources. Specifically, Cloudfront Distribution and Lamba@Edge associated with it.
I see Cloudfront distribution is just being disabled: https://github.com/serverless-nextjs/serverless-next.js/blob/6f68bf1910d80cc69b09f6529081e6ccad74552e/packages/serverless-components/aws-cloudfront/lib/index.js#L319
It would be great if the component had an option to wait for it to be disabled and delete it (and also the associated lambda). I know this might take much longer so perhaps it could be made optional.
AFAIK, you can wait for distribution to be disabled by aws cloudfront wait distribution-deployed --id $id.
This would be nice. However deleting the associated lambda is a little tricky. If you refer to https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-edge-delete-replicas.html,
You can delete a Lambda@Edge function only when the replicas of the function have been deleted by CloudFront Replicas are typically deleted within a few hours. You cannot manually delete Lambda@Edge function replicas
So I'm not sure if is feasible to do this via the remove command.
I remember thinking in the past we could have some sort of background cleanup task for this but that feels outside of the scope of this project tbh.
Deleting the cloudfront distribution should not be a problem. It is usually disabled in ~3 minutes. We're using the following snippet to delete it:
aws cloudfront wait distribution-deployed --id $DISTRIBUTION_ID
ETAG=$(aws cloudfront get-distribution-config --id $DISTRIBUTION_ID | jq -r '.ETag')
aws cloudfront delete-distribution --id $DISTRIBUTION_ID --if-match $ETAG
This will delete the CF distribution and trigger the cleanup of replicated lambdas and help people avoid the quota limit on number of cloudfront distributions associated with Lambda@Edge (25 afaik).
As for the cleanup of deleting lambdas, I'm still investigating a good solution.
@Meemaw did you got any solution so far for deleting lambdas