终止 AWS Elastic Beanstalk 环境

Posted

技术标签:

【中文标题】终止 AWS Elastic Beanstalk 环境【英文标题】:Terminating AWS Elastic Beanstalk environment 【发布时间】:2021-09-29 06:05:27 【问题描述】:

我想终止我的 AWS Elastic Beanstalk 环境,但我想保留与该环境关联的 RDS 数据库实例的快照。

我已经成功创建了相关 RDS 数据库的快照,但是当我去终止 Elastic Beanstalk 环境时,它说这样做会:

用快照终止database-in-question

这是否意味着我创建的快照以及数据库实例将被删除?如果是这样,我怎样才能避免快照被删除?

【问题讨论】:

它应该要求你保留快照。它不这样做吗? @Marcin 不,不幸的是它没有要求我保留快照... 你去RDS控制台做手动快照了吗? @Marcin 我想是的;我做了:操作 > 在 RDS 控制台的数据库区域中拍摄快照 您可以按照以下步骤保留rds备份-> aws.amazon.com/premiumsupport/knowledge-center/… 【参考方案1】:

Elastic Beanstalk 在后台使用 CloudFormation 来预置您的环境。 CloudFormation 的工作原理是它有一个堆栈,其中包含它创建的所有资源,并且一旦您删除了 Beanstalk 环境,该堆栈就会被删除。因此,它将删除作为堆栈一部分的所有资源。您可以在控制台中转到 CloudFormation 并查看它。

如果您手动创建了数据库快照,它将位于 CloudFormation 堆栈之外,因此不会被删除。

但是,作为 Beanstalk 环境设置的一部分,您的 DB 会有一些自动备份。当您终止您的环境时,这些将被删除。

这是我的测试环境堆栈:

$ aws cloudformation describe-stack-resources --stack-name awseb-e-jjqgv3nwgp-stack --profile=personal

    "StackResources": [
        [...],
        
            "StackName": "awseb-e-jjqgv3nwgp-stack",
            "StackId": "arn:aws:cloudformation:eu-central-1:[my_account]:stack/awseb-e-jjqgv3nwgp-stack/f21c2e00-ea6d-11eb-9f61-02ad9e7e97f6",
            "LogicalResourceId": "AWSEBRDSDBSecurityGroup",
            "PhysicalResourceId": "awseb-e-jjqgv3nwgp-stack-AWSEBRDSDBSecurityGroup-1SDABJ60VF7G8",
            "ResourceType": "AWS::EC2::SecurityGroup",
            "Timestamp": "2021-07-21T21:52:52.931000+00:00",
            "ResourceStatus": "CREATE_COMPLETE",
            "DriftInformation": 
                "StackResourceDriftStatus": "NOT_CHECKED"
            
        ,
        
            "StackName": "awseb-e-jjqgv3nwgp-stack",
            "StackId": "arn:aws:cloudformation:eu-central-1:[my_account]:stack/awseb-e-jjqgv3nwgp-stack/f21c2e00-ea6d-11eb-9f61-02ad9e7e97f6",
            "LogicalResourceId": "AWSEBRDSDatabase",
            "PhysicalResourceId": "aa1v9kyuepq8x1c",
            "ResourceType": "AWS::RDS::DBInstance",
            "Timestamp": "2021-07-21T21:59:24.817000+00:00",
            "ResourceStatus": "CREATE_COMPLETE",
            "DriftInformation": 
                "StackResourceDriftStatus": "NOT_CHECKED"
            
        ,
        [...]
    ]


这是我的 RDS 快照:

$ aws rds describe-db-snapshots --profile=personal

    "DBSnapshots": [
        
            "DBSnapshotIdentifier": "foobar-snapshot-test",
            "DBInstanceIdentifier": "aa1v9kyuepq8x1c",
            "SnapshotCreateTime": "2021-07-21T22:09:03.752000+00:00",
            "Engine": "mysql",
            "AllocatedStorage": 5,
            "Status": "available",
            "Port": 3306,
            "AvailabilityZone": "eu-central-1a",
            "VpcId": "vpc-128d5178",
            "InstanceCreateTime": "2021-07-21T21:56:51.205000+00:00",
            "MasterUsername": "foo",
            "EngineVersion": "8.0.23",
            "LicenseModel": "general-public-license",
            "SnapshotType": "manual",
            "OptionGroupName": "default:mysql-8-0",
            "PercentProgress": 100,
            "StorageType": "standard",
            "Encrypted": false,
            "DBSnapshotArn": "arn:aws:rds:eu-central-1:[my_account]:snapshot:foobar-snapshot-test",
            "IAMDatabaseAuthenticationEnabled": false,
            "ProcessorFeatures": [],
            "DbiResourceId": "db-PFQFQBRFBELDWUQTONIPRJRVCU",
            "TagList": []
        ,
        
            "DBSnapshotIdentifier": "rds:aa1v9kyuepq8x1c-2021-07-21-21-57",
            "DBInstanceIdentifier": "aa1v9kyuepq8x1c",
            "SnapshotCreateTime": "2021-07-21T21:57:05.277000+00:00",
            "Engine": "mysql",
            "AllocatedStorage": 5,
            "Status": "available",
            "Port": 3306,
            "AvailabilityZone": "eu-central-1a",
            "VpcId": "vpc-128d5178",
            "InstanceCreateTime": "2021-07-21T21:56:51.205000+00:00",
            "MasterUsername": "foo",
            "EngineVersion": "8.0.23",
            "LicenseModel": "general-public-license",
            "SnapshotType": "automated",
            "OptionGroupName": "default:mysql-8-0",
            "PercentProgress": 100,
            "StorageType": "standard",
            "Encrypted": false,
            "DBSnapshotArn": "arn:aws:rds:eu-central-1:[my_account]:snapshot:rds:aa1v9kyuepq8x1c-2021-07-21-21-57",
            "IAMDatabaseAuthenticationEnabled": false,
            "ProcessorFeatures": [],
            "DbiResourceId": "db-PFQFQBRFBELDWUQTONIPRJRVCU",
            "TagList": []
        
    ]

所以,我们有一份自动快照和一份手动快照。

删除应用程序后,CloudFormation 堆栈被移除,剩下的是手动快照,但自动快照已被删除:

$ aws rds describe-db-snapshots --profile=personal

    "DBSnapshots": [
        
            "DBSnapshotIdentifier": "foobar-snapshot-test",
            "DBInstanceIdentifier": "aa1v9kyuepq8x1c",
            "SnapshotCreateTime": "2021-07-21T22:09:03.752000+00:00",
            "Engine": "mysql",
            "AllocatedStorage": 5,
            "Status": "available",
            "Port": 3306,
            "AvailabilityZone": "eu-central-1a",
            "VpcId": "vpc-128d5178",
            "InstanceCreateTime": "2021-07-21T21:56:51.205000+00:00",
            "MasterUsername": "foo",
            "EngineVersion": "8.0.23",
            "LicenseModel": "general-public-license",
            "SnapshotType": "manual",
            "OptionGroupName": "default:mysql-8-0",
            "PercentProgress": 100,
            "StorageType": "standard",
            "Encrypted": false,
            "DBSnapshotArn": "arn:aws:rds:eu-central-1:[my_account]:snapshot:foobar-snapshot-test",
            "IAMDatabaseAuthenticationEnabled": false,
            "ProcessorFeatures": [],
            "DbiResourceId": "db-PFQFQBRFBELDWUQTONIPRJRVCU",
            "TagList": []
        
    ]


在终止 Beanstalk 上的任何内容之前,您始终可以仔细检查您的 RDS 快照以确保那里有手动快照。

【讨论】:

以上是关于终止 AWS Elastic Beanstalk 环境的主要内容,如果未能解决你的问题,请参考以下文章

AWS Elastic Beanstalk:在运行 PHP 的 EC2 实例上终止 HTTPS

AWS Elastic Beanstalk 错误 - 乘客

替换 AWS Elastic BeanStalk 上的特定实例?

将应用程序部署到 AWS Elastic Beanstalk 环境

AWS Elastic Beanstalk / NodeJS / Nginx 错误:不断收到 502 bad gateway

AWS Elastic Beanstalk 上的 Rails 应用程序:错误的 nginx 配置