AWS Amplify: How to delete the environment, when resources are already partially deleted?
Asked Answered
P

5

23

TL;DR: How to delete an amplify environment, when some resources of the service have been deleted manually in the console?

So, I took a course on egghead to learn the aws amplify CLI. Unfortunately, it doesn't teach you how to delete the environment (otherwise it's great though!). My google search back then said you will have to delete the resources manually. I tried (/did) that for the resources I used. I deleted the user account for the CLI (🤦🏻‍♂️), "deleted" the cognito user pool (it still shows up in amplify status), deleted the DynamoDB and the AppSync API (also still shows up).

Now as I mentioned when I run amplify status I get:

| Category | Resource name   | Operation | Provider plugin   |
| -------- | --------------- | --------- | ----------------- |
| Auth     | cognito559c5953 | No Change | awscloudformation |
| Api      | AmplifyTodoApp  | No Change | awscloudformation |

I wondered - since I thought I deleted them - do they still exist?

So I googled some more. Now it turns out there is also the command amplify delete which automatically deletes all resources associated with your amplify project. Since I deleted the account that I used for the project, that command throws:

The security token included in the request is invalid.

Is there any way I can delete these resources without the user? Are these resources even still online (since I manually deleted them and they do not show up in the console online - even in the CloudFront console)? Or will I have to delete my whole AWS account? I don't want to end up with a big bill one day for these resources.

EDIT: I also deleted the S3 bucket.

EDIT 2: So I managed to use another profile (by changing local-aws-info.json) so I don't get the security request failed error any more. Now I get the error:

Missing region in config

amplify status still yields the same response.

Portugal answered 14/3, 2019 at 8:42 Comment(0)
K
27

amplify cli determines the status by diffing amplify/#current-cloud-backend and amplify/backend folder inside your project. So what you see when you run amplify status you see isn't accurate in your case.

If you have created multiple environments (in different regions) make sure that you delete them too. The easiest way to delete them if you can't use amplify delete is to go to cloud formation in the region where you have created the environment and deleting the root stack, which ensures that all the resources created by that stack are removed.

PS: The cli creates roles for auth and unauth users when initialized and creates policies for the resources (they don't cost anything if they exist). You could delete them if you don't want them hanging around.

Kennard answered 15/3, 2019 at 0:18 Comment(2)
how might i remove the policies that "were" attached to the now deleted stack. are the orphaned, nameless and homeless now??Fabria
I think you have to go to Cognito and remove them.Cutwater
I
5

When some resources have been deleted manually (S3 & Cloudformation) then

$amplify delete  

Gives Following :

Unable to remove env: dev because deployment bucket amplify-amplifyAPPName-dev-XYZ-deployment does not exist or has been deleted.
  
Stack has already been deleted or does not exist

Please look at this:

C:user\samadhan\Amplify-Projects\amplifyapp-demo>amplify delete

? Are you sure you want to continue? This CANNOT be undone. (This will delete all the environments of the project from the cloud and wi
pe out all the local files created by Amplify CLI) Yes
- Deleting resources from the cloud. This may take a few minutes...
Deleting env: dev.
Unable to remove env: dev because deployment bucket amplify- 
amplifyinitdemo-dev-131139-deployment does not exist or has been deleted.

Stack has already been deleted or does not exist

\ Deleting resources from the cloud. This may take a few minutes...App 
 dfwx13s2bgtb1 not found.

App dfwx13s2bgtb1 not found.
√ Project already deleted in the cloud.
Project deleted locally.

App Amplify App still showing in Console Unable to delete from Console. Please Take a look : Amplify App Console Unable to Delete App Error

Solution: Using AWS CLI You Can be Fixed This Issue. Step 1 ) Make Sure AWS CLI is configured with the Same AWS Account if Not Please Create IAM User & Configure it with the same Region.

C:user\samadhan\Amplify-Projects\amplifyapp-demo>aws configure
AWS Access Key ID [****************HZHF]: ****************ICHK
AWS Secret Access Key [****************iBJl]:****************SnaX
Default region name [ap-south-1]: ap-south-1
Default output format [json]: json

Step 2 ) Use Following AWS CLI Commands.

C:user\samadhan\Amplify-Projects\amplifyapp-demo>>aws amplify help
Available Commands
******************
* create-app
* create-backend-environment
* create-deployment
* delete-app
* delete-backend-environment
* get-app
* list-apps
* list-backend-environments

C:user\samadhan\Amplify-Projects\amplifyapp-demo>aws amplify list-apps
{
    "apps": [
        {
        "appId": "d39pvb2qln4v7l",
        "appArn": "arn:aws:amplify:ap-south-1:850915XXXXX:apps/d39pvb2qln4v7l",
        "name": "react-amplify-demo-project",
            "tags": {},
            "platform": "WEB",
            "createTime": 1640206703.371,
            "updateTime": 1640206703.371,
            "environmentVariables": {
                "_LIVE_PACKAGE_UPDATES": "[{\"pkg\":\"@aws-amplify/cli\",\"type\":\"npm\",\"version\":\"latest\"}]"
            },
        {
            "appId": "d2jsl78ex1asqy",
            "appArn": "arn:aws:amplify:ap-south-1:85091xxxxxxxx:apps/d2jsl78ex1asqy",
            "name": "fullstackapp",
            "tags": {},
            "platform": "WEB",
            "createTime": 1640250148.974,
            "updateTime": 1640250148.974,
            "environmentVariables": {
                "_LIVE_PACKAGE_UPDATES": "[{\"pkg\":\"@aws-amplify/cli\",\"type\":\"npm\",\"version\":\"latest\"}]"
            }
        }

Step 3) Use Following CLI Command to Delete App Or App Env

C:user\samadhan\Amplify-Projects\amplifyapp-demo>aws amplify delete-app --app-id d39pvb2qln4v7l
{
    "app": {
        "appId": "d39pvb2qln4v7l",
        "appArn": "arn:aws:amplify:ap-south-1:8509xxxxx:apps/d39pvb2qln4v7l",
        "name": "react-amplify-demo-project",
        "repository": "https://gitlab.com/samadhanfuke/react-amplify-demo-project",
        "platform": "WEB",
        "createTime": 1639077857.194,
        "updateTime": 1639077857.194,
        "iamServiceRoleArn": "arn:aws:iam::850915xxxx:role/amplifyconsole-backend-role",
        "environmentVariables": {
            "_LIVE_UPDATES": "[{\"name\":\"Amplify CLI\",\"pkg\":\"@aws-amplify/cli\",\"type\":\"npm\",\"version\":\"latest\"}]"
        },
        "defaultDomain": "d39pvb2qln4v7l.amplifyapp.com",
        "enableBranchAutoBuild": false,
        "enableBranchAutoDeletion": false,
        "enableBasicAuth": false,
        "customRules": [
            {
                "source": "/<*>",
                "target": "/index.html",
                "status": "404-200"
            }
        ],
        "productionBranch": {
            "lastDeployTime": 1639078272.607,
            "status": "SUCCEED",
            "branchName": "preview"
        },
        "buildSpec": "version: 1\nbackend:\n  phases:\n    # IMPORTANT - Please verify your build commands\n    build:\n      commands:\n        - '# Execute Amplify CLI with the helper script'\n        - amplifyPush --simple\nfrontend:\n  phases:\n    build:\n      commands: []\n  artifacts:\n    # IMPORTANT - Please verify your build output directory\n    baseDirectory: /\n    files:\n      - '**/*'\n  cache:\n    paths: []\n",
        "customHeaders": "",
        "enableAutoBranchCreation": false
    }
}

Amplify App With Environment Successfully Deleted. Check-in Amplify Console.

Impost answered 26/12, 2021 at 12:17 Comment(0)
F
0

As of 9/26/2022 several updates have been released that fix issues deleting apps/backends, including issues where the s3 bucket or cloudformation stack was already deleted

Fredra answered 27/9, 2022 at 1:15 Comment(0)
T
0

Note that deleting the amplify application as documented here, does not remove the resources created in S3. You need to delete these manually.

The content in the bucket amplify-{project name}-{env name}-{some id}-deployment is created and updated when you run amplify init, amplify push among others. It appears to be used as the remote synchronisation directory.

The S3 buckets will be recreated by the amplify root CloudFormation stack, whenever you create a new env or run amplify init.

Topnotch answered 29/9, 2022 at 10:34 Comment(0)
T
0

With Amplify CLI v12.12.4 now you can use following to remove an environment from Local as well as from Remote:

amplify env remove <environment_name>

Note:

  • You cannot remove your current selected environment. You must checkout to some other env first.
  • This can be used if you haven't already deleted any resources.
Trappings answered 24/7, 2024 at 10:58 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.