AWS Amplify:当资源已被部分删除时,如何删除环境?
Posted
技术标签:
【中文标题】AWS Amplify:当资源已被部分删除时,如何删除环境?【英文标题】:AWS Amplify: How to delete the environment, when resources are already partially deleted? 【发布时间】:2019-08-05 02:09:48 【问题描述】:TL;DR:当服务的某些资源在控制台中被手动删除时,如何删除放大环境?
所以,我参加了一个关于 Egghead 的课程来学习 aws amplify CLI。不幸的是,它没有教你如何删除环境(否则它很棒!)。我当时的谷歌搜索说你必须手动删除资源。我尝试(/做了)我使用的资源。我删除了 CLI 的用户帐户 (????????♂️),“删除”了 cognito 用户池(它仍然显示在 amplify status
),删除了 DynamoDB 和 AppSync API(仍然显示上)。
正如我在运行amplify status
时提到的那样,我得到:
| Category | Resource name | Operation | Provider plugin |
| -------- | --------------- | --------- | ----------------- |
| Auth | cognito559c5953 | No Change | awscloudformation |
| Api | AmplifyTodoApp | No Change | awscloudformation |
我想知道——因为我以为我删除了它们——它们还存在吗?
所以我用谷歌搜索了更多。现在事实证明还有命令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
仍然产生相同的响应。
【问题讨论】:
【参考方案1】:amplify cli 通过区分项目中的 amplify/#current-cloud-backend
和 amplify/backend
文件夹来确定状态。因此,您在运行 amplify status
时看到的内容在您的情况下并不准确。
如果您创建了多个环境(在不同区域),请确保也将它们删除。如果您不能使用amplify delete
,则删除它们的最简单方法是在您创建环境的区域和deleting 根堆栈中转到云形成,这样可以确保删除该堆栈创建的所有资源.
PS: cli 在初始化时为auth
和unauth
用户创建角色,并为资源创建策略(如果它们存在,它们不会花费任何成本)。如果您不希望它们闲逛,可以删除它们。
【讨论】:
我怎样才能删除“已”附加到现在已删除的堆栈的策略。现在是孤儿、无名、无家可归了吗?? 我认为你必须去 Cognito 并删除它们。【参考方案2】:当手动删除一些资源(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 控制台。
【讨论】:
以上是关于AWS Amplify:当资源已被部分删除时,如何删除环境?的主要内容,如果未能解决你的问题,请参考以下文章
在 AWS Amplify 中更改我的 GraphQL 架构时如何防止丢失生产数据?
AWS Amplify cloudformation parameter.json 如何工作?
AWS- Amplify - Appsync:使用 CLI 从 Android 应用程序更改云资源时,正确的工作流程是啥?