【问题标题】:How to get the most recent shared AWS RDS snapshot by id?如何通过 id 获取最新的共享 AWS RDS 快照?
【发布时间】:2020-05-21 22:00:48
【问题描述】:

我在 AWS RDS 上有 2 个数据库,一个用于 stage,一个用于 production,跨 2 个账户。我正在尝试每 x 天将 production 中的数据复制到 stage。我的计划是在production 中创建最新的自动备份快照的副本,并在使用production 中的共享快照在stage 中创建数据库之前将其共享到stage 帐户。一切都很顺利,直到我遇到了我认为是错误的错误,但很可能是我犯了错误。

当我尝试使用 data "aws_db_snapshot" 在 Terraform 中获取 ID 为 abcd 的最新共享快照时,我没有得到任何结果。

data "aws_db_snapshot" "latest_prod_snapshot" {
  db_instance_identifier = "abcd"
  snapshot_type          = "shared"
  include_shared         = "true"
  most_recent            = "true"
}

然后我决定试用 AWS CLI。当我运行这个...

aws rds describe-db-snapshots --snapshot-type shared --include-shared

...我明白了...

{
    "DBSnapshots": [
        {
            "MasterUsername": "root", 
            "LicenseModel": "general-public-license", 
            "InstanceCreateTime": "2018-01-13T00:00:00.000Z", 
            "Engine": "mysql", 
            "VpcId": "vpc-0000000000000000", 
            "SourceRegion": "us-east-1", 
            "AllocatedStorage": 20, 
            "Status": "available", 
            "PercentProgress": 100, 
            "SourceDBSnapshotIdentifier": "arn:aws:rds:us-east-1:000000000000:snapshot:rds:abcd-2020-01-13-00-00", 
            "DBSnapshotIdentifier": "arn:aws:rds:us-east-1:000000000000:snapshot:rds:abcd-2020-01-13-00-00", 
            "DBSnapshotArn": "arn:aws:rds:us-east-1:000000000000:snapshot:rds:abcd-2020-01-13-00-00", 
            "EngineVersion": "5.6.41", 
            "ProcessorFeatures": [], 
            "OptionGroupName": "default:mysql-5-6", 
            "SnapshotCreateTime": "2020-01-13T00:00:00.000Z", 
            "AvailabilityZone": "us-east-1b", 
            "StorageType": "gp2", 
            "Encrypted": false, 
            "IAMDatabaseAuthenticationEnabled": false, 
            "DbiResourceId": "db-AAAAAAAAAAAAAAAAAAAAAAAAA", 
            "SnapshotType": "shared", 
            "Port": 3306, 
            "DBInstanceIdentifier": "abcd"
        }
    ]
}

...这是我所期望的。查看响应,我希望数据库实例 id 为 abcd 但是当我运行它时......

aws rds describe-db-snapshots --snapshot-type shared --include-shared --db-instance-identifier abcd

...或者这个...

aws rds describe-db-snapshots --snapshot-type shared --include-shared --filters Name=db-instance-id,Values=abcd

...我明白了...

{
    "DBSnapshots": []
}

...这不是我所期望的。这是一个错误还是我做错了什么?我查看了他们的文档,但我可能遗漏了一些东西。

【问题讨论】:

  • 我同意。我设法重现了你的结果。基本上,当为共享快照指定数据库实例 ID 时,结果集为空。相同的命令在“相同”(非共享)帐户中工作正常。 AWS CLI 和 boto3 都会发生这种情况。如果您有 AWS 支持计划,则应使用此信息创建支持票证。
  • 很遗憾,我没有可以获得技术支持的支持计划。

标签: amazon-web-services terraform amazon-rds aws-cli terraform-provider-aws


【解决方案1】:

在我们等待 AWS 解决此问题的同时。以下是您可以做的一些解决方法:

  1. stage 帐户中复制共享快照并使用副本而不是共享。
  2. 在 Terraform 中,回滚到较旧的提供程序版本。

2.27 为我工作

provider "aws" {
  version                 = "2.27.0"
}

【讨论】:

    【解决方案2】:

    根据 AWS Support,DBInstanceIdentifier 仅用于显示调用客户拥有的快照的结果,因此不返回共享快照的结果。为了使用 DBInstanceIdentifier 仅过滤和显示共享快照,可以使用 --query 按 DBInstanceIdentifier 值进行过滤:

    aws rds describe-db-snapshots --snapshot-type shared --include-shared --query "DBSnapshots[?DBInstanceIdentifier=='abcd']" 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-01
      • 2020-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多