Aktualisieren eines -Clusters - Amazon Aurora DSQL

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Aktualisieren eines -Clusters

In den folgenden Informationen erfahren Sie, wie Sie einen Cluster in Aurora DSQL aktualisieren. Die Aktualisierung eines Clusters kann ein oder zwei Minuten dauern. Wir empfehlen, einige Zeit zu warten und dann get cluster auszuführen, um den Status des Clusters abzurufen.

Python

Verwenden Sie das folgende Beispiel, um einen Cluster mit einer oder mehreren Regionen zu aktualisieren.

import boto3 def update_cluster(region, cluster_id, deletion_protection_enabled): try: client = boto3.client("dsql", region_name=region) return client.update_cluster(identifier=cluster_id, deletionProtectionEnabled=deletion_protection_enabled) except: print("Unable to update cluster") raise def main(): region = "us-east-1" cluster_id = "<your cluster id>" deletion_protection_enabled = False response = update_cluster(region, cluster_id, deletion_protection_enabled) print(f"Updated {response["arn"]} with deletion_protection_enabled: {deletion_protection_enabled}") if __name__ == "__main__": main()
C++

Verwenden Sie das folgende Beispiel, um einen Cluster mit einer oder mehreren Regionen zu aktualisieren.

#include <aws/core/Aws.h> #include <aws/core/utils/Outcome.h> #include <aws/dsql/DSQLClient.h> #include <aws/dsql/model/UpdateClusterRequest.h> #include <iostream> using namespace Aws; using namespace Aws::DSQL; using namespace Aws::DSQL::Model; /** * Updates a cluster in Amazon Aurora DSQL */ UpdateClusterResult UpdateCluster(const Aws::String& region, const Aws::Map<Aws::String, Aws::String>& updateParams) { // Create client for the specified region DSQL::DSQLClientConfiguration clientConfig; clientConfig.region = region; DSQL::DSQLClient client(clientConfig); // Create update request UpdateClusterRequest updateRequest; updateRequest.SetClientToken(Aws::Utils::UUID::RandomUUID()); // Set identifier (required) if (updateParams.find("identifier") != updateParams.end()) { updateRequest.SetIdentifier(updateParams.at("identifier")); } else { throw std::runtime_error("Cluster identifier is required for update operation"); } // Set deletion protection if specified if (updateParams.find("deletion_protection_enabled") != updateParams.end()) { bool deletionProtection = (updateParams.at("deletion_protection_enabled") == "true"); updateRequest.SetDeletionProtectionEnabled(deletionProtection); } // Execute the update auto updateOutcome = client.UpdateCluster(updateRequest); if (!updateOutcome.IsSuccess()) { std::cerr << "Failed to update cluster: " << updateOutcome.GetError().GetMessage() << std::endl; throw std::runtime_error("Unable to update cluster"); } return updateOutcome.GetResult(); } int main() { Aws::SDKOptions options; Aws::InitAPI(options); { try { // Define region and update parameters Aws::String region = "us-east-1"; Aws::String clusterId = "<your cluster id>"; // Create parameter map Aws::Map<Aws::String, Aws::String> updateParams; updateParams["identifier"] = clusterId; updateParams["deletion_protection_enabled"] = "false"; auto updatedCluster = UpdateCluster(region, updateParams); std::cout << "Updated " << updatedCluster.GetArn() << std::endl; } catch (const std::exception& e) { std::cerr << "Error: " << e.what() << std::endl; } } Aws::ShutdownAPI(options); return 0; }
JavaScript

Verwenden Sie das folgende Beispiel, um einen Cluster mit einer oder mehreren Regionen zu aktualisieren.

import { DSQLClient, UpdateClusterCommand } from "@aws-sdk/client-dsql"; export async function updateCluster(region, clusterId, deletionProtectionEnabled) { const client = new DSQLClient({ region }); const updateClusterCommand = new UpdateClusterCommand({ identifier: clusterId, deletionProtectionEnabled: deletionProtectionEnabled }); try { return await client.send(updateClusterCommand); } catch (error) { console.error("Unable to update cluster", error.message); throw error; } } async function main() { const region = "us-east-1"; const clusterId = "<CLUSTER_ID>"; const deletionProtectionEnabled = false; const response = await updateCluster(region, clusterId, deletionProtectionEnabled); console.log(`Updated ${response.arn}`); } main();
Java

Verwenden Sie das folgende Beispiel, um einen Cluster mit einer oder mehreren Regionen zu aktualisieren.

package org.example; import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.dsql.DsqlClient; import software.amazon.awssdk.services.dsql.model.UpdateClusterRequest; import software.amazon.awssdk.services.dsql.model.UpdateClusterResponse; public class UpdateCluster { public static void main(String[] args) { Region region = Region.US_EAST_1; String clusterId = "<your cluster id>"; try ( DsqlClient client = DsqlClient.builder() .region(region) .credentialsProvider(DefaultCredentialsProvider.create()) .build() ) { UpdateClusterRequest request = UpdateClusterRequest.builder() .identifier(clusterId) .deletionProtectionEnabled(false) .build(); UpdateClusterResponse cluster = client.updateCluster(request); System.out.println("Updated " + cluster.arn()); } } }
Rust

Verwenden Sie das folgende Beispiel, um einen Cluster mit einer oder mehreren Regionen zu aktualisieren.

use aws_config::load_defaults; use aws_sdk_dsql::operation::update_cluster::UpdateClusterOutput; use aws_sdk_dsql::{ Client, Config, config::{BehaviorVersion, Region}, }; /// 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) } /// Update a DSQL cluster and set delete protection to false. Also add new tags. pub async fn update_cluster(region: &'static str, identifier: &'static str) -> UpdateClusterOutput { let client = dsql_client(region).await; // Update delete protection let update_response = client .update_cluster() .identifier(identifier) .deletion_protection_enabled(false) .send() .await .unwrap(); update_response } #[tokio::main(flavor = "current_thread")] pub async fn main() -> anyhow::Result<()> { let region = "us-east-1"; let cluster = update_cluster(region, "<your cluster id>").await; println!("{:#?}", cluster); Ok(()) }
Ruby

Verwenden Sie das folgende Beispiel, um einen Cluster mit einer oder mehreren Regionen zu aktualisieren.

require "aws-sdk-dsql" def update_cluster(region, update_params) client = Aws::DSQL::Client.new(region: region) client.update_cluster(update_params) rescue Aws::Errors::ServiceError => e abort "Unable to update cluster: #{e.message}" end def main region = "us-east-1" cluster_id = "<your cluster id>" updated_cluster = update_cluster(region, { identifier: cluster_id, deletion_protection_enabled: false }) puts "Updated #{updated_cluster.arn}" end main if $PROGRAM_NAME == __FILE__
.NET

Verwenden Sie das folgende Beispiel, um einen Cluster mit einer oder mehreren Regionen zu aktualisieren.

using System; using System.Threading.Tasks; using Amazon; using Amazon.DSQL; using Amazon.DSQL.Model; using Amazon.Runtime.Credentials; namespace DSQLExamples.examples { public class UpdateCluster { /// <summary> /// Create a client. We will use this later for performing operations on the cluster. /// </summary> private static async Task<AmazonDSQLClient> CreateDSQLClient(RegionEndpoint region) { var awsCredentials = await DefaultAWSCredentialsIdentityResolver.GetCredentialsAsync(); var clientConfig = new AmazonDSQLConfig { RegionEndpoint = region }; return new AmazonDSQLClient(awsCredentials, clientConfig); } /// <summary> /// Update a DSQL cluster and set delete protection to false. /// </summary> public static async Task<UpdateClusterResponse> Update(RegionEndpoint region, string identifier) { using (var client = await CreateDSQLClient(region)) { var updateClusterRequest = new UpdateClusterRequest { Identifier = identifier, DeletionProtectionEnabled = false }; UpdateClusterResponse response = await client.UpdateClusterAsync(updateClusterRequest); Console.WriteLine($"Updated {response.Arn}"); return response; } } private static async Task Main() { var region = RegionEndpoint.USEast1; var clusterId = "<your cluster id>"; await Update(region, clusterId); } } }
Golang

Verwenden Sie das folgende Beispiel, um einen Cluster mit einer oder mehreren Regionen zu aktualisieren.

package main import ( "context" "github.com/aws/aws-sdk-go-v2/config" "log" "time" "github.com/aws/aws-sdk-go-v2/service/dsql" ) func UpdateCluster(ctx context.Context, region, id string, deleteProtection bool) (clusterStatus *dsql.UpdateClusterOutput, err error) { cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion(region)) if err != nil { log.Fatalf("Failed to load AWS configuration: %v", err) } // Initialize the DSQL client client := dsql.NewFromConfig(cfg) input := dsql.UpdateClusterInput{ Identifier: &id, DeletionProtectionEnabled: &deleteProtection, } clusterStatus, err = client.UpdateCluster(context.Background(), &input) if err != nil { log.Fatalf("Failed to update cluster: %v", err) } log.Printf("Cluster updated successfully: %v", clusterStatus.Status) return clusterStatus, nil } func main() { ctx, cancel := context.WithTimeout(context.Background(), 6*time.Minute) defer cancel() // Example cluster identifier identifier := "<CLUSTER_ID>" region := "us-east-1" deleteProtection := false _, err := UpdateCluster(ctx, region, identifier, deleteProtection) if err != nil { log.Fatalf("Failed to update cluster: %v", err) } }