AWS Amplify:当资源已被部分删除时,如何删除环境?

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

TL;DR:如何在控制台中手动删除服务的某些资源时删除放大环境?

所以,我参加了 egghead 的课程来学习 aws amplify CLI。不幸的是,它没有教您如何删除环境(否则它很棒!)。我的 google 搜索当时说您必须手动删除资源。对于我使用的资源,我尝试过(/做过)。我删除了 CLI (‍♂️) 的用户帐户,"deleted" 认知用户池(它仍然显示在 amplify status 中),删除了 DynamoDB 和 AppSync API(也仍然显示向上)。

现在正如我在 运行 amplify status 时提到的,我得到:

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

我想知道 - 因为我以为我删除了它们 - 它们还存在吗?

所以我 google 多了一些。现在发现还有命令 amplify delete 会自动删除与您的放大项目关联的所有资源。由于我删除了用于该项目的帐户,该命令抛出:

The security token included in the request is invalid.

有什么办法可以在没有用户的情况下删除这些资源吗?这些资源是否仍然在线(因为我手动删除了它们并且它们没有在线显示在控制台中 - 即使在 CloudFront 控制台中也是如此)?或者我必须删除我的整个 AWS 账户吗?我不想有一天为这些资源支付一大笔账单。

编辑: 我还删除了 S3 存储桶。

编辑 2: 所以我设法使用了另一个配置文件(通过更改 local-aws-info.json)所以我不再收到安全请求失败错误。现在我得到错误:

Missing region in config

amplify status 仍然会产生相同的响应。

amplify cli 通过比较项目中的 amplify/#current-cloud-backendamplify/backend 文件夹来确定状态。因此,当您 运行 amplify status 看到的内容在您的情况下并不准确。

如果您创建了多个环境(在不同地区),请确保也将它们删除。如果您不能使用 amplify delete 删除它们,最简单的方法是在您创建环境的区域和 deleting 根堆栈中进行云形成,这确保了创建的所有资源该堆栈已删除。

PS: cli 在初始化时为 authunauth 用户创建角色并为资源创建策略(他们不如果它们存在,则不会花费任何费用)。如果你不想让它们闲逛,你可以删除它们。

当一些资源被手动删除后(S3 和 Cloudformation)然后

$amplify delete  

给出如下:

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

请看这个:

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 仍然显示在控制台中无法从控制台中删除。 请看一下 :

解法: 使用 AWS CLI 可以解决此问题。 步骤 1) 确保 AWS CLI 配置了相同的 AWS 账户,如果不是请创建 IAM 用户并使用相同的区域配置它.

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

步骤 2) 使用以下 AWS CLI 命令。

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\"}]"
            }
        }

步骤 3) 使用以下 CLI 命令删除 App 或 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 控制台。