Amazon Aurora DSQL is provided as a Preview service.
To learn more, see Betas and Previews
Amazon Aurora DSQL is provided as a Preview service.
To learn more, see Betas and Previews
Get a cluster in Aurora DSQL with the AWS SDKs
See the following information to learn how to return information a a cluster in Aurora DSQL.
- Python
-
To get information about a single or a multi-Region cluster, use the following example.
import boto3 def get_cluster(cluster_id, client): try: return client.get_cluster(identifier=cluster_id) except: print("Unable to get cluster") raise def main(): region = "us-east-1" client = boto3.client("dsql", region_name=region) cluster_id = "foo0bar1baz2quux3quuux4" response = get_cluster(cluster_id, client) print("Cluster Status: " + response['status']) if __name__ == "__main__": main()
- C++
-
Use the following example to get information about a single or a multi-Region cluster.
#include <aws/core/Aws.h> #include <aws/dsql/DSQLClient.h> #include <aws/dsql/model/GetClusterRequest.h> #include <aws/dsql/model/ClusterStatus.h> #include <iostream> using namespace Aws; using namespace Aws::DSQL; using namespace Aws::DSQL::Model; ClusterStatus getCluster(const String& clusterId, DSQLClient& client) { GetClusterRequest request; request.SetIdentifier(clusterId); GetClusterOutcome outcome = client.GetCluster(request); ClusterStatus status = ClusterStatus::NOT_SET; if (outcome.IsSuccess()) { const auto& cluster = outcome.GetResult(); status = cluster.GetStatus(); } else { std::cerr << "Get operation failed: " << outcome.GetError().GetMessage() << std::endl; } std::cout << "Cluster Status: " << ClusterStatusMapper::GetNameForClusterStatus(status) << std::endl; return status; } int main() { Aws::SDKOptions options; Aws::InitAPI(options); DSQLClientConfiguration clientConfig; clientConfig.region = "us-east-1"; DSQLClient client(clientConfig); String clusterId = "foo0bar1baz2quux3quuux4"; getCluster(clusterId, client); Aws::ShutdownAPI(options); return 0; }
- JavaScript
-
To get information about a single or multi-Region cluster, use the following example.
import { DSQLClient } from "@aws-sdk/client-dsql"; import { GetClusterCommand } from "@aws-sdk/client-dsql"; async function getCluster(clusterId, client) { const getClusterCommand = new GetClusterCommand({ identifier: clusterId, }); try { return await client.send(getClusterCommand); } catch (error) { if (error.name === "ResourceNotFoundException") { console.log("Cluster ID not found or deleted"); } else { console.error("Unable to poll cluster status:", error.message); } throw error; } } async function main() { const region = "us-east-1"; const client = new DSQLClient({ region }); const clusterId = "foo0bar1baz2quux3quuux4"; const response = await getCluster(clusterId, client); console.log("Cluster Status:", response.status); } main()
- Java
-
The following example lets you get information about a single or multi-Region cluster.
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration; import software.amazon.awssdk.core.retry.RetryMode; import software.amazon.awssdk.http.urlconnection.UrlConnectionHttpClient; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.retries.StandardRetryStrategy; import software.amazon.awssdk.services.dsql.DsqlClient; import software.amazon.awssdk.services.dsql.model.GetClusterRequest; import software.amazon.awssdk.services.dsql.model.GetClusterResponse; import software.amazon.awssdk.services.dsql.model.ResourceNotFoundException; import java.net.URI; public class GetCluster { public static void main(String[] args) { Region region = Region.US_EAST_1; ClientOverrideConfiguration clientOverrideConfiguration = ClientOverrideConfiguration.builder() .retryStrategy(StandardRetryStrategy.builder().build()) .build(); DsqlClient client = DsqlClient.builder() .httpClient(UrlConnectionHttpClient.create()) .overrideConfiguration(clientOverrideConfiguration) .region(region) .credentialsProvider(DefaultCredentialsProvider.create()) .build(); String cluster_id = "foo0bar1baz2quux3quuux4"; GetClusterResponse response = getCluster(cluster_id, client); System.out.println("cluster status: " + response.status()); } public static GetClusterResponse getCluster(String cluster_id, DsqlClient client) { GetClusterRequest getClusterRequest = GetClusterRequest.builder() .identifier(cluster_id) .build(); try { return client.getCluster(getClusterRequest); } catch (ResourceNotFoundException rnfe) { System.out.println("Cluster id is not found / deleted"); throw rnfe; } catch (Exception e) { System.out.println(("Unable to poll cluster status: " + e.getMessage())); throw e; } } }
- Rust
-
The following example lets you get information about a single or multi-Region cluster.
use aws_config::load_defaults; use aws_sdk_dsql::{config::{BehaviorVersion, Region}, Client, Config}; use aws_sdk_dsql::operation::get_cluster::GetClusterOutput; /// Create a client. We will use this later for performing operations on the cluster. async fn dsql_client(region: &'static str) -> Client { // Load default SDK configuration let sdk_defaults = load_defaults(BehaviorVersion::latest()).await; // You can set your own credentials by following this guide // https://docs.aws.amazon.com/sdk-for-rust/latest/dg/credproviders.html let credentials = sdk_defaults .credentials_provider() .unwrap(); let config = Config::builder() .behavior_version(BehaviorVersion::latest()) .credentials_provider(credentials) .region(Region::new(region)) .build(); Client::from_conf(config) } // Get a ClusterResource from DSQL cluster identifier pub async fn get_cluster( region: &'static str, identifier: String, ) -> GetClusterOutput { let client = dsql_client(region).await; client .get_cluster() .identifier(identifier) .send() .await .unwrap() } #[tokio::main(flavor = "current_thread")] pub async fn main() -> anyhow::Result<()> { let region = "us-east-1"; get_cluster(region, "<your cluster id>".to_owned()).await; Ok(()) }
- Ruby
-
The following example lets you get information about a single or multi-Region cluster.
require 'aws-sdk-core' require 'aws-sdk-dsql' def get_cluster(region, identifier) begin # Create client with default configuration and credentials client = Aws::DSQL::Client.new(region: region) client.get_cluster( identifier: identifier ) rescue Aws::Errors::ServiceError => e raise "Failed to get cluster details: #{e.message}" end end
- .NET
-
The following example lets you get information about a single or multi-Region cluster.
using Amazon.DSQL; using Amazon.DSQL.Model; using Amazon.Runtime; class GetCluster { public static async Task<GetClusterResponse> Get(RegionEndpoint region, string clusterId) { // Create the sdk client AWSCredentials awsCredentials = FallbackCredentialsFactory.GetCredentials(); AmazonDSQLConfig clientConfig = new() { AuthenticationServiceName = "dsql", RegionEndpoint = region }; AmazonDSQLClient client = new(awsCredentials, clientConfig); // Get cluster details GetClusterRequest getClusterRequest = new() { Identifier = clusterId }; // Assert that operation is successful GetClusterResponse getClusterResponse = await client.GetClusterAsync(getClusterRequest); Console.WriteLine(getClusterResponse.Status); return getClusterResponse; } }
To get information about a single or a multi-Region cluster, use the following example.
import boto3
def get_cluster(cluster_id, client):
try:
return client.get_cluster(identifier=cluster_id)
except:
print("Unable to get cluster")
raise
def main():
region = "us-east-1"
client = boto3.client("dsql", region_name=region)
cluster_id = "foo0bar1baz2quux3quuux4"
response = get_cluster(cluster_id, client)
print("Cluster Status: " + response['status'])
if __name__ == "__main__":
main()