RDS generate_presigned_url does not support the DestinationRegion parameter

Viewed 701

I was trying to set up encrypted RDS replica in another region, but I got stuck on generating pre-signed URL.

It seems that boto3/botocore does not allow DestinationRegion parameter, which is defined as a requirement on AWS API (link) in case we want to generate PreSignedUrl.

Versions used:

  • boto3 (1.4.7)
  • botocore (1.7.10)

Output:

botocore.exceptions.ParamValidationError: Parameter validation failed:
Unknown parameter in input: "DestinationRegion", must be one of: DBInstanceIdentifier, SourceDBInstanceIdentifier, DBInstanceClass, AvailabilityZone, Port, AutoMinorVersionUpgrade, Iops, OptionGroupName, PubliclyAccessible, Tags, DBSubnetGroupName, StorageType, CopyTagsToSnapshot, MonitoringInterval, MonitoringRoleArn, KmsKeyId, PreSignedUrl, EnableIAMDatabaseAuthentication, SourceRegion

Example code:

import boto3

url = boto3.client('rds', 'eu-east-1').generate_presigned_url(
    ClientMethod='create_db_instance_read_replica',
    Params={
        'DestinationRegion': 'eu-east-1',
        'SourceDBInstanceIdentifier': 'abc',
        'KmsKeyId': '1234',
        'DBInstanceIdentifier': 'someidentifier'
        },
    ExpiresIn=3600,
    HttpMethod=None
    )

Same issue was already reported but got closed.

Thanks for help,

Petar

1 Answers

Generate Pre signed URL from the source region, then populate the create_db_instance_read_replica with that url.

The presigned URL must be a valid request for the CreateDBInstanceReadReplica API action that can be executed in the source AWS Region that contains the encrypted source DB instance

PreSignedUrl (string) -- The URL that contains a Signature Version 4 signed request for the CreateDBInstanceReadReplica API action in the source AWS Region that contains the source DB instance.

import boto3

session = boto3.Session(profile_name='profile_name')

url = session.client('rds', 'SOURCE_REGION').generate_presigned_url(
    ClientMethod='create_db_instance_read_replica',
    Params={
        'DBInstanceIdentifier': 'db-1-read-replica',
        'SourceDBInstanceIdentifier': 'database-source',
        'SourceRegion': 'SOURCE_REGION'
    },
    ExpiresIn=3600,
    HttpMethod=None
)

print(url)

source_db = session.client('rds', 'SOURCE_REGION').describe_db_instances(
    DBInstanceIdentifier='database-SOURCE'
)

print(source_db)

response = session.client('rds', 'DESTINATION_REGION').create_db_instance_read_replica(
    SourceDBInstanceIdentifier="arn:aws:rds:SOURCE_REGION:account_number:db:database-SOURCE",
    DBInstanceIdentifier="db-1-read-replica",
    KmsKeyId='DESTINATION_REGION_KMS_ID',
    PreSignedUrl=url,
    SourceRegion='SOURCE'
)

print(response)
Related