- how to destroy cloud infrastructure previously deployed for project applications (possibly into multiple environments)
The destroy Command
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 three project applications, all previously deployed into the dev environment:
yarn webiny destroy api --env dev
yarn webiny destroy apps/admin --env dev
yarn webiny destroy apps/website --env devDebugging
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 the prod environment? 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, such as the default DynamoDB table or the default Cognito User Pool
, 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, for starters, unmark all cloud resources as protected, which can be done by setting the protectedEnvironment (api/pulumi/prod/index.ts) flag to
false.
Once that’s in place, run the webiny deploy command to apply changes, and finally, run the webiny destroy to destroy everything.
Troubleshooting
Destroying my project takes a long time to finish.
We’re aware of this fact, and this is mainly because of the Amazon ElasticSearch Service . While other cloud infrastructure resources get destroyed reasonably fast, this service can take anywhere from 15 to 30 minutes to destroy itself. In rare cases, we’ve even seen the service still present in user’s account for days
.
Unfortunately, this is a well-known issue for quite some time, and until the present, there haven’t been any positive improvements.