Infrastructure > Basics
Destroy Cloud Infrastructure
Learn how to destroy the cloud infrastructure deployed for your project applications, using the Webiny CLI.
- how to destroy cloud infrastructure previously deployed for project applications (possibly into multiple environments)
ThedestroyCommand
This command lets you destroy cloud infrastructure previously deployed within a project application.
As its first argument, the destroy command receives the path to the project application folder. You also need to specify the environment into which the cloud infrastructure was previously deployed, which is specified via the --env argument.
The following destroy commands destroy cloud infrastructure deployed for four project applications, all previously deployed into the dev environment:
yarn webiny destroy website --env dev
yarn webiny destroy admin --env dev
yarn webiny destroy api --env dev
yarn webiny destroy core --env devTo fully destroy your project, you can also run the command without specifying the project application folder:
yarn webiny destroy --env dev --confirm-destroy-env devNote that, upon doing this, the command will ask for a confirmation of the environment you wish to destroy, via the --confirm-destroy-env flag.
Debugging
If you run into an error while running the webiny destroy command, to get additional information and logs about it, you can append the --debug argument. For example:
yarn webiny destroy api --env dev --debugThis can significantly help in debugging underlying deployment (Pulumi) errors, since without it, in some cases the returned error report doesn’t contain enough useful information. We’ve also seen cases in which the report would actually be misleading and even incorrect, making the debugging process much harder for the user.
FAQ
How Do I Destroy Cloud Infrastructure Resources Deployed Into theprodEnvironment? I'm Receiving a Warning About Protected Cloud Infrastructure Resources.
When deploying into the prod environment, some of the cloud infrastructure resources that Webiny deploys for you as part of the Core project application are marked as protected.
The
protectoption marks a resource as protected. A protected resource cannot be deleted directly. Instead, you must first setprotect: falseand runpulumi up. Then you can delete the resource by removing the line of code or by runningpulumi destroy. The default is to inherit this value from the parent resource, andfalsefor resources without a parent.
Within a Webiny project, note that the pulumi up and pulumi destroy commands are run via the webiny deploy and webiny destroy commands, respectively.
So, in order to destroy all cloud infrastructure resources deployed into the prod environment, we need to first pass protect: false upon calling the createCoreApp function in apps/core/webiny.application.ts:
import { createCoreApp } from "@webiny/serverless-cms-aws";
export default createCoreApp({
protect: false
});Once that’s in place, run the webiny deploy command to apply changes, and finally, run the webiny destroy to destroy everything:
# Removes the protection from mission-critical cloud infrastructure resources.
yarn webiny deploy core --env prod
# At this point, the protection has been removed. We can now run the destroy command.
yarn webiny destroy core --env prodOnce that has been destroyed, you can proceed with destroying the rest of the project applications, which do not contain any protected cloud infrastructure resources.
yarn webiny destroy api --env prod
yarn webiny destroy admin --env prod
yarn webiny destroy website --env prodTroubleshooting
Upon Destroying My Webiny Project, I've Received a "PreconditionFailed" Error Message. What Can I Do?
On multiple occasions, we’ve seen users receive the following error upon destroying their Webiny project:
pulumi:pulumi:Stack (website-dev):
error: update failed
aws:cloudfront:Distribution (delivery):
error: deleting urn:pulumi:dev::website::aws:cloudfront/distribution:Distribution::delivery: 1 error occurred:
* CloudFront Distribution {DISTRIBUTION_ID} cannot be deleted: PreconditionFailed: The request failed because it didn't meet the preconditions in one or more request-header fields.
status code: 412, request id: {REQUEST_ID}As we can see, the error is related to deleting an Amazon Cloudfront distribution that’s deployed as part of the Website project application.
As mentioned in this GitHub issue, this error can happen because of the fact that many operations within AWS silently mutate Cloudfront distributions’ ETAG
. This causes the subsequent update (delete) attempts to fail.
Ultimately, this issue can be resolved by refreshing your Pulumi state files, by running the following command:
yarn webiny pulumi website --env dev -- refresh --skip-preview --yesDestroying My Project Takes a Long Time to Finish.
We’re aware of this fact, and this is mainly because of the Amazon OpenSearch Service. While other cloud infrastructure resources get destroyed reasonably fast, this service can take anywhere from 15 to 30 minutes to destroy itself.