import boto3
# Create an RDS client
rds = boto3.client('rds')
# Define the source snapshot and the new DB instance parameters
source_snapshot_id = 'my-source-snapshot-id'
new_db_instance_id = 'my-new-db-instance-id'
new_db_instance_class = 'db.t2.micro'
new_db_instance_engine = 'postgres'
# Restore the new DB instance from the source snapshot
response = rds.restore_db_instance_from_db_snapshot(
DBSnapshotIdentifier=source_snapshot_id,
DBInstanceIdentifier=new_db_instance_id,
DBInstanceClass=new_db_instance_class,
Engine=new_db_instance_engine,
PubliclyAccessible=True
)
This code restores a new DB instance from the snapshot identified by my-source-snapshot-id
, and assigns it the ID my-new-db-instance-id
. The new DB instance will have the class db.t2.micro
and use the PostgreSQL engine. It will also be publicly accessible.
You can find more information about the restore_db_instance_from_db_snapshot()
method and the other available RDS methods in the AWS RDS API Reference.