How to get the most recent shared AWS RDS snapshot by id?

不打扰是莪最后的温柔 提交于 2020-03-02 09:47:01

问题


I have 2 databases on AWS RDS, one for stage and one for production across 2 accounts. I am trying to copy the data in production to stage every x days. My plan was to make a copy of the most recent automatic backup snapshot in production and share it to the stage account before creating the database in stage using the shared snapshot from production. Everything was going right until I ran into what I believe is a bug but it could easily be that I made a mistake.

When I tried to get the most recent, shared, snapshot with an id of abcd in Terraform with data "aws_db_snapshot", I got no results.

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

Then I decided to try out AWS CLI. When I run this...

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

... I get this...

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

... which is what I expected. Looking at the response, I would expect the db instance id to be abcd but when I run this...

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

... or this...

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

... I get this...

{
    "DBSnapshots": []
}

... which is not what I would have expected. Is this a bug or am I doing something wrong? I looked through their documentation but I may have missed something.


回答1:


While we wait for AWS to fix this. Here are some things you can do as workaround:

  1. In the stage account copy the shared snapshot and use the copy instead of the shared.
  2. In Terraform, rollback to an older provider version.

2.27 works for me

provider "aws" {
  version                 = "2.27.0"
}


来源:https://stackoverflow.com/questions/60085106/how-to-get-the-most-recent-shared-aws-rds-snapshot-by-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!