Use DescribeDBClusterSnapshots with an Amazon SDK or CLI - Amazon Aurora
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Use DescribeDBClusterSnapshots with an Amazon SDK or CLI

The following code examples show how to use DescribeDBClusterSnapshots.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

.NET
Amazon SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

/// <summary> /// Return a list of DB snapshots for a particular DB cluster. /// </summary> /// <param name="dbClusterIdentifier">DB cluster identifier.</param> /// <returns>List of DB snapshots.</returns> public async Task<List<DBClusterSnapshot>> DescribeDBClusterSnapshotsByIdentifierAsync(string dbClusterIdentifier) { var results = new List<DBClusterSnapshot>(); DescribeDBClusterSnapshotsResponse response; DescribeDBClusterSnapshotsRequest request = new DescribeDBClusterSnapshotsRequest { DBClusterIdentifier = dbClusterIdentifier }; // Get the full list if there are multiple pages. do { response = await _amazonRDS.DescribeDBClusterSnapshotsAsync(request); results.AddRange(response.DBClusterSnapshots); request.Marker = response.Marker; } while (response.Marker is not null); return results; }
C++
SDK for C++
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region (overrides config file). // clientConfig.region = "us-east-1"; Aws::RDS::RDSClient client(clientConfig); Aws::RDS::Model::DescribeDBClusterSnapshotsRequest request; request.SetDBClusterSnapshotIdentifier(snapshotID); Aws::RDS::Model::DescribeDBClusterSnapshotsOutcome outcome = client.DescribeDBClusterSnapshots(request); if (outcome.IsSuccess()) { snapshot = outcome.GetResult().GetDBClusterSnapshots()[0]; } else { std::cerr << "Error with Aurora::DescribeDBClusterSnapshots. " << outcome.GetError().GetMessage() << std::endl; cleanUpResources(CLUSTER_PARAMETER_GROUP_NAME, DB_CLUSTER_IDENTIFIER, DB_INSTANCE_IDENTIFIER, client); return false; }
Go
SDK for Go V2
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

type DbClusters struct { AuroraClient *rds.Client } // GetClusterSnapshot gets a DB cluster snapshot. func (clusters *DbClusters) GetClusterSnapshot(snapshotName string) (*types.DBClusterSnapshot, error) { output, err := clusters.AuroraClient.DescribeDBClusterSnapshots(context.TODO(), &rds.DescribeDBClusterSnapshotsInput{ DBClusterSnapshotIdentifier: aws.String(snapshotName), }) if err != nil { log.Printf("Couldn't get snapshot %v: %v\n", snapshotName, err) return nil, err } else { return &output.DBClusterSnapshots[0], nil } }
Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

public static void waitForSnapshotReady(RdsClient rdsClient, String dbSnapshotIdentifier, String dbInstanceClusterIdentifier) { try { boolean snapshotReady = false; String snapshotReadyStr; System.out.println("Waiting for the snapshot to become available."); DescribeDbClusterSnapshotsRequest snapshotsRequest = DescribeDbClusterSnapshotsRequest.builder() .dbClusterSnapshotIdentifier(dbSnapshotIdentifier) .dbClusterIdentifier(dbInstanceClusterIdentifier) .build(); while (!snapshotReady) { DescribeDbClusterSnapshotsResponse response = rdsClient.describeDBClusterSnapshots(snapshotsRequest); List<DBClusterSnapshot> snapshotList = response.dbClusterSnapshots(); for (DBClusterSnapshot snapshot : snapshotList) { snapshotReadyStr = snapshot.status(); if (snapshotReadyStr.contains("available")) { snapshotReady = true; } else { System.out.println("."); Thread.sleep(sleepTime * 5000); } } } System.out.println("The Snapshot is available!"); } catch (RdsException | InterruptedException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } }
Kotlin
SDK for Kotlin
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

suspend fun waitSnapshotReady( dbSnapshotIdentifier: String?, dbInstanceClusterIdentifier: String?, ) { var snapshotReady = false var snapshotReadyStr: String println("Waiting for the snapshot to become available.") val snapshotsRequest = DescribeDbClusterSnapshotsRequest { dbClusterSnapshotIdentifier = dbSnapshotIdentifier dbClusterIdentifier = dbInstanceClusterIdentifier } RdsClient { region = "us-west-2" }.use { rdsClient -> while (!snapshotReady) { val response = rdsClient.describeDbClusterSnapshots(snapshotsRequest) val snapshotList = response.dbClusterSnapshots if (snapshotList != null) { for (snapshot in snapshotList) { snapshotReadyStr = snapshot.status.toString() if (snapshotReadyStr.contains("available")) { snapshotReady = true } else { println(".") delay(slTime * 5000) } } } } } println("The Snapshot is available!") }
Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

class AuroraWrapper: """Encapsulates Aurora DB cluster actions.""" def __init__(self, rds_client): """ :param rds_client: A Boto3 Amazon Relational Database Service (Amazon RDS) client. """ self.rds_client = rds_client @classmethod def from_client(cls): """ Instantiates this class from a Boto3 client. """ rds_client = boto3.client("rds") return cls(rds_client) def get_cluster_snapshot(self, snapshot_id): """ Gets a DB cluster snapshot. :param snapshot_id: The ID of the snapshot to retrieve. :return: The retrieved snapshot. """ try: response = self.rds_client.describe_db_cluster_snapshots( DBClusterSnapshotIdentifier=snapshot_id ) snapshot = response["DBClusterSnapshots"][0] except ClientError as err: logger.error( "Couldn't get DB cluster snapshot %s. Here's why: %s: %s", snapshot_id, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return snapshot

For a complete list of Amazon SDK developer guides and code examples, see Using this service with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.