TL;DR: 当在控制台中手动删除了服务的某些资源时,如何删除 amplify 环境?
因此,我参加了有关蛋头的课程来学习 aws amplify CLI。不幸的是,它不会教您如何删除环境(否则它就很棒了!)。我当时的谷歌搜索说你必须手动删除资源。我尝试(/做过)我使用的资源。我删除了 CLI 的用户帐户 (🤦🏻u200d♂️),“删除”了 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
会自动删除与您的 amplify 项目关联的所有资源。由于我删除了用于该项目的帐户,该命令会抛出:
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-backend
和 amplify/backend
文件夹来确定状态。因此,当您运行 amplify status
时看到的内容在您的情况下并不准确。
如果您创建了多个环境(在不同区域),请确保也删除它们。如果无法使用
amplify delete
,删除它们的最简单方法是在创建环境的区域中进行云形成并删除根堆栈,这可确保删除该堆栈创建的所有资源.
PS: cli 在初始化时为
auth
和 unauth
用户创建角色,并为资源创建策略(如果存在,它们不会产生任何费用)。如果您不想让它们继续存在,您可以删除它们。
当手动删除某些资源(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 应用程序仍显示在控制台中无法从控制台删除。 请看一下 :
解决方案: 使用 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 命令删除应用程序或应用程序环境
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 控制台。
截至 2022 年 9 月 26 日,已发布多个更新,修复删除应用程序/后端的问题,包括 s3 存储桶或 cloudformation 堆栈已被删除的问题
请注意,删除此处记录的放大应用程序不会删除在 S3 中创建的资源。您需要手动删除这些。
当您运行
amplify init
、amplify push
等时,会创建并更新存储桶 amplify-{project name}-{env name}-{some id}-deployment 中的内容。好像是用来做远程同步目录的。
每当您创建新环境或运行
amplify init
时,放大根 CloudFormation 堆栈都会重新创建 S3 存储桶。
使用 Amplify CLI v12.12.4 现在,您可以使用以下命令从本地和远程删除环境:
放大环境删除
注: