Ada lebih banyak AWS SDK contoh yang tersedia di GitHub repo SDKContoh AWS Dokumen
Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Gunakan DescribeDBClusterParameters
dengan AWS SDK
Contoh kode berikut menunjukkan cara menggunakanDescribeDBClusterParameters
.
Contoh tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Anda dapat melihat tindakan ini dalam konteks dalam contoh kode berikut:
- .NET
-
- AWS SDK for .NET
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. /// <summary> /// Describe the cluster parameters in a parameter group. /// </summary> /// <param name="groupName">The name of the parameter group.</param> /// <param name="source">The optional name of the source filter.</param> /// <returns>The collection of parameters.</returns> public async Task<List<Parameter>> DescribeDBClusterParametersInGroupAsync(string groupName, string? source = null) { var paramList = new List<Parameter>(); DescribeDBClusterParametersResponse response; var request = new DescribeDBClusterParametersRequest { DBClusterParameterGroupName = groupName, Source = source, }; // Get the full list if there are multiple pages. do { response = await _amazonRDS.DescribeDBClusterParametersAsync(request); paramList.AddRange(response.Parameters); request.Marker = response.Marker; } while (response.Marker is not null); return paramList; }
-
Untuk API detailnya, lihat D escribeDBCluster Parameter dalam AWS SDK for .NET APIReferensi.
-
- C++
-
- SDKuntuk C ++
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region (overrides config file). // clientConfig.region = "us-east-1"; Aws::RDS::RDSClient client(clientConfig); //! Routine which gets DB parameters using the 'DescribeDBClusterParameters' api. /*! \sa getDBCLusterParameters() \param parameterGroupName: The name of the cluster parameter group. \param namePrefix: Prefix string to filter results by parameter name. \param source: A source such as 'user', ignored if empty. \param parametersResult: Vector of 'Parameter' objects returned by the routine. \param client: 'RDSClient' instance. \return bool: Successful completion. */ bool AwsDoc::Aurora::getDBCLusterParameters(const Aws::String ¶meterGroupName, const Aws::String &namePrefix, const Aws::String &source, Aws::Vector<Aws::RDS::Model::Parameter> ¶metersResult, const Aws::RDS::RDSClient &client) { Aws::String marker; // The marker is used for pagination. do { Aws::RDS::Model::DescribeDBClusterParametersRequest request; request.SetDBClusterParameterGroupName(CLUSTER_PARAMETER_GROUP_NAME); if (!marker.empty()) { request.SetMarker(marker); } if (!source.empty()) { request.SetSource(source); } Aws::RDS::Model::DescribeDBClusterParametersOutcome outcome = client.DescribeDBClusterParameters(request); if (outcome.IsSuccess()) { const Aws::Vector<Aws::RDS::Model::Parameter> ¶meters = outcome.GetResult().GetParameters(); for (const Aws::RDS::Model::Parameter ¶meter: parameters) { if (!namePrefix.empty()) { if (parameter.GetParameterName().find(namePrefix) == 0) { parametersResult.push_back(parameter); } } else { parametersResult.push_back(parameter); } } marker = outcome.GetResult().GetMarker(); } else { std::cerr << "Error with Aurora::DescribeDBClusterParameters. " << outcome.GetError().GetMessage() << std::endl; return false; } } while (!marker.empty()); return true; }
-
Untuk API detailnya, lihat D escribeDBCluster Parameter dalam AWS SDK for C++ APIReferensi.
-
- Go
-
- SDKuntuk Go V2
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. import ( "context" "errors" "log" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/rds" "github.com/aws/aws-sdk-go-v2/service/rds/types" ) type DbClusters struct { AuroraClient *rds.Client } // GetParameters gets the parameters that are contained in a DB cluster parameter group. func (clusters *DbClusters) GetParameters(ctx context.Context, parameterGroupName string, source string) ( []types.Parameter, error) { var output *rds.DescribeDBClusterParametersOutput var params []types.Parameter var err error parameterPaginator := rds.NewDescribeDBClusterParametersPaginator(clusters.AuroraClient, &rds.DescribeDBClusterParametersInput{ DBClusterParameterGroupName: aws.String(parameterGroupName), Source: aws.String(source), }) for parameterPaginator.HasMorePages() { output, err = parameterPaginator.NextPage(ctx) if err != nil { log.Printf("Couldn't get paramaeters for %v: %v\n", parameterGroupName, err) break } else { params = append(params, output.Parameters...) } } return params, err }
-
Untuk API detailnya, lihat D escribeDBCluster Parameter
dalam AWS SDK for Go APIReferensi.
-
- Java
-
- SDKuntuk Java 2.x
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. public static void describeDbClusterParameters(RdsClient rdsClient, String dbCLusterGroupName, int flag) { try { DescribeDbClusterParametersRequest dbParameterGroupsRequest; if (flag == 0) { dbParameterGroupsRequest = DescribeDbClusterParametersRequest.builder() .dbClusterParameterGroupName(dbCLusterGroupName) .build(); } else { dbParameterGroupsRequest = DescribeDbClusterParametersRequest.builder() .dbClusterParameterGroupName(dbCLusterGroupName) .source("user") .build(); } DescribeDbClusterParametersResponse response = rdsClient .describeDBClusterParameters(dbParameterGroupsRequest); List<Parameter> dbParameters = response.parameters(); String paraName; for (Parameter para : dbParameters) { // Only print out information about either auto_increment_offset or // auto_increment_increment. paraName = para.parameterName(); if ((paraName.compareTo("auto_increment_offset") == 0) || (paraName.compareTo("auto_increment_increment ") == 0)) { System.out.println("*** The parameter name is " + paraName); System.out.println("*** The parameter value is " + para.parameterValue()); System.out.println("*** The parameter data type is " + para.dataType()); System.out.println("*** The parameter description is " + para.description()); System.out.println("*** The parameter allowed values is " + para.allowedValues()); } } } catch (RdsException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } }
-
Untuk API detailnya, lihat D escribeDBCluster Parameter dalam AWS SDK for Java 2.x APIReferensi.
-
- Kotlin
-
- SDKuntuk Kotlin
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. suspend fun describeDbClusterParameters( dbCLusterGroupName: String?, flag: Int, ) { val dbParameterGroupsRequest: DescribeDbClusterParametersRequest dbParameterGroupsRequest = if (flag == 0) { DescribeDbClusterParametersRequest { dbClusterParameterGroupName = dbCLusterGroupName } } else { DescribeDbClusterParametersRequest { dbClusterParameterGroupName = dbCLusterGroupName source = "user" } } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.describeDbClusterParameters(dbParameterGroupsRequest) response.parameters?.forEach { para -> // Only print out information about either auto_increment_offset or auto_increment_increment. val paraName = para.parameterName if (paraName != null) { if (paraName.compareTo("auto_increment_offset") == 0 || paraName.compareTo("auto_increment_increment ") == 0) { println("*** The parameter name is $paraName") println("*** The parameter value is ${para.parameterValue}") println("*** The parameter data type is ${para.dataType}") println("*** The parameter description is ${para.description}") println("*** The parameter allowed values is ${para.allowedValues}") } } } } }
-
Untuk API detailnya, lihat D escribeDBCluster Parameter AWS
SDKuntuk API referensi Kotlin.
-
- Python
-
- SDKuntuk Python (Boto3)
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. 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_parameters(self, parameter_group_name, name_prefix="", source=None): """ Gets the parameters that are contained in a DB cluster parameter group. :param parameter_group_name: The name of the parameter group to query. :param name_prefix: When specified, the retrieved list of parameters is filtered to contain only parameters that start with this prefix. :param source: When specified, only parameters from this source are retrieved. For example, a source of 'user' retrieves only parameters that were set by a user. :return: The list of requested parameters. """ try: kwargs = {"DBClusterParameterGroupName": parameter_group_name} if source is not None: kwargs["Source"] = source parameters = [] paginator = self.rds_client.get_paginator("describe_db_cluster_parameters") for page in paginator.paginate(**kwargs): parameters += [ p for p in page["Parameters"] if p["ParameterName"].startswith(name_prefix) ] except ClientError as err: logger.error( "Couldn't get parameters for %s. Here's why: %s: %s", parameter_group_name, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return parameters
-
Untuk API detailnya, lihat D escribeDBCluster Parameter AWS SDKuntuk Referensi Python (Boto3). API
-
- Rust
-
- SDKuntuk Rust
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. // Get the parameter group. rds.DescribeDbClusterParameterGroups // Get parameters in the group. This is a long list so you will have to paginate. Find the auto_increment_offset and auto_increment_increment parameters (by ParameterName). rds.DescribeDbClusterParameters // Parse the ParameterName, Description, and AllowedValues values and display them. pub async fn cluster_parameters(&self) -> Result<Vec<AuroraScenarioParameter>, ScenarioError> { let parameters_output = self .rds .describe_db_cluster_parameters(DB_CLUSTER_PARAMETER_GROUP_NAME) .await; if let Err(err) = parameters_output { return Err(ScenarioError::new( format!("Failed to retrieve parameters for {DB_CLUSTER_PARAMETER_GROUP_NAME}"), &err, )); } let parameters = parameters_output .unwrap() .into_iter() .flat_map(|p| p.parameters.unwrap_or_default().into_iter()) .filter(|p| FILTER_PARAMETER_NAMES.contains(p.parameter_name().unwrap_or_default())) .map(AuroraScenarioParameter::from) .collect::<Vec<_>>(); Ok(parameters) } pub async fn describe_db_cluster_parameters( &self, name: &str, ) -> Result<Vec<DescribeDbClusterParametersOutput>, SdkError<DescribeDBClusterParametersError>> { self.inner .describe_db_cluster_parameters() .db_cluster_parameter_group_name(name) .into_paginator() .send() .try_collect() .await } #[tokio::test] async fn test_scenario_cluster_parameters() { let mut mock_rds = MockRdsImpl::default(); mock_rds .expect_describe_db_cluster_parameters() .with(eq("RustSDKCodeExamplesDBParameterGroup")) .return_once(|_| { Ok(vec![DescribeDbClusterParametersOutput::builder() .parameters(Parameter::builder().parameter_name("a").build()) .parameters(Parameter::builder().parameter_name("b").build()) .parameters( Parameter::builder() .parameter_name("auto_increment_offset") .build(), ) .parameters(Parameter::builder().parameter_name("c").build()) .parameters( Parameter::builder() .parameter_name("auto_increment_increment") .build(), ) .parameters(Parameter::builder().parameter_name("d").build()) .build()]) }); let mut scenario = AuroraScenario::new(mock_rds); scenario.db_cluster_identifier = Some("RustSDKCodeExamplesDBCluster".into()); let params = scenario.cluster_parameters().await.expect("cluster params"); let names: Vec<String> = params.into_iter().map(|p| p.name).collect(); assert_eq!( names, vec!["auto_increment_offset", "auto_increment_increment"] ); } #[tokio::test] async fn test_scenario_cluster_parameters_error() { let mut mock_rds = MockRdsImpl::default(); mock_rds .expect_describe_db_cluster_parameters() .with(eq("RustSDKCodeExamplesDBParameterGroup")) .return_once(|_| { Err(SdkError::service_error( DescribeDBClusterParametersError::unhandled(Box::new(Error::new( ErrorKind::Other, "describe_db_cluster_parameters_error", ))), Response::new(StatusCode::try_from(400).unwrap(), SdkBody::empty()), )) }); let mut scenario = AuroraScenario::new(mock_rds); scenario.db_cluster_identifier = Some("RustSDKCodeExamplesDBCluster".into()); let params = scenario.cluster_parameters().await; assert_matches!(params, Err(ScenarioError { message, context: _ }) if message == "Failed to retrieve parameters for RustSDKCodeExamplesDBParameterGroup"); }
-
Untuk API detailnya, lihat D escribeDBCluster Parameter AWS
SDKuntuk API referensi Rust.
-