Skip to content
This repository was archived by the owner on Jan 28, 2025. It is now read-only.
This repository was archived by the owner on Jan 28, 2025. It is now read-only.

CDK destroy fails due to replicated lambdas #2432

@james-wallis

Description

@james-wallis

Issue Summary

Stack deletion fails using either cdk destroy or the Cloudformation UI with the error below.

I waited until I was able to test 3.8.0-alpha.0 which contains #2420 as I hoped that it would solve my issue but no luck.

Workaround

Not sure if this is a viable fix but it seems to work.

Stack Overflow thread contains a workaround for CDK ignoring the retain option. Adding this to my CDK code gives me:

const nextJsApp = new NextJSLambdaEdge(this, "NextJsApp", {
  serverlessBuildOutDir: "./build",
  description,
  cloudfrontProps: {
    comment: stackName,
  },
  domain: {
    domainNames: [primaryDomain, wwwDomain],
    hostedZone: parentHostedZone,
    certificate,
  },
});
// Workaround begins here
const defaultLambda = nextJsApp.defaultNextLambda.node.defaultChild as cdk.CfnResource;
defaultLambda.applyRemovalPolicy(cdk.RemovalPolicy.RETAIN);

Actual behavior

cdk destroy fails with:

11:06:45 | DELETE_FAILED        | AWS::Lambda::Function                           | NextJsAppNextLambdaBA081175
Resource handler returned message: "Lambda was unable to delete arn:aws:lambda:us-east-1:ACC_UID:function:my-app-NextJsAppNextLambdaBA081-SrJH98LTjLHK:2 because it is a replicated function. Please see our document
ation for Deleting Lambda@Edge Functions and Replicas. (Service: Lambda, Status Code: 400, Request ID: a2dc3a8b-0576-4643-8b62-92a183d544b2)" (RequestToken: 9255da9c-31aa-2046-9f1c-91de1a7b1716, HandlerErrorCode: InvalidRequest)

...

destroy failed Error: The stack named my-app is in a failed state. You may need to delete it from the AWS console : DELETE_FAILED (The following resource(s) failed to delete: [NextJsAppNextLambdaBA081175]. )
    at waitForStackDelete (/node_modules/aws-cdk/lib/api/util/cloudformation.ts:279:11)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at destroyStack (/node_modules/aws-cdk/lib/api/deploy-stack.ts:452:28)
    at CdkToolkit.destroy (/node_modules/aws-cdk/lib/cdk-toolkit.ts:381:9)
    at initCommandLine (/node_modules/aws-cdk/lib/cli.ts:312:12)

The stack named my-app is in a failed state. You may need to delete it from the AWS console : DELETE_FAILED (The following resource(s) failed to delete: [NextJsAppNextLambdaBA081175]. )

Note: For the error above I had deleted all API routes, but when added their lambda also fails with the same error.

Expected behavior

The cdk destroy to exit cleanly without deleting the API Lambdas as they are marked as RETAIN.

Steps to reproduce

Deploy using the CDK, destroy either using CDK or the Cloudformation UI.

Screenshots/Code/Configuration/Logs

Versions

  • OS/Environment: MacOS
  • @sls-next/serverless-component version: 3.8.0-alpha.0 (And latest 3.7)
  • Next.js version: 12.1.4

Additional context

Checklist

  • You have reviewed the README and FAQs, which answers several common questions.
  • You have reviewed our DEBUGGING wiki and have tried your best to include complete information and reproduction steps (including your configuration) as is possible. As there is only one maintainer (who maintains this in his free time) and thus very limited resources, if you have time, please try to debug the issue a bit yourself if possible.
  • You have first tried using the most recent latest or alpha @sls-next/serverless-component release version, which may have already fixed your issue or implemented the feature you are trying to use. Note that the old serverless-next.js component and the serverless-next.js plugin are deprecated and no longer maintained.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions