将 DescribeOrderableDBInstanceOptions
与 AWS SDK 或 CLI 配合使用
以下代码示例演示如何使用 DescribeOrderableDBInstanceOptions
。
操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:
- .NET
-
- AWS SDK for .NET
-
注意
查看 GitHub,了解更多信息。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 /// <summary> /// Get a list of orderable DB instance options for a specific /// engine and engine version. /// </summary> /// <param name="engine">Name of the engine.</param> /// <param name="engineVersion">Version of the engine.</param> /// <returns>List of OrderableDBInstanceOptions.</returns> public async Task<List<OrderableDBInstanceOption>> DescribeOrderableDBInstanceOptionsPagedAsync(string engine, string engineVersion) { // Use a paginator to get a list of DB instance options. var results = new List<OrderableDBInstanceOption>(); var paginateInstanceOptions = _amazonRDS.Paginators.DescribeOrderableDBInstanceOptions( new DescribeOrderableDBInstanceOptionsRequest() { Engine = engine, EngineVersion = engineVersion, }); // Get the entire list using the paginator. await foreach (var instanceOptions in paginateInstanceOptions.OrderableDBInstanceOptions) { results.Add(instanceOptions); } return results; }
-
有关 API 详细信息,请参阅《AWS SDK for .NET API 参考》中的 DescribeOrderableDBInstanceOptions。
-
- C++
-
- SDK for C++
-
注意
查看 GitHub,了解更多信息。查找完整示例,学习如何在 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 available DB instance classes, displays the list //! to the user, and returns the user selection. /*! \sa chooseDBInstanceClass() \param engineName: The DB engine name. \param engineVersion: The DB engine version. \param dbInstanceClass: String for DB instance class chosen by the user. \param client: 'RDSClient' instance. \return bool: Successful completion. */ bool AwsDoc::Aurora::chooseDBInstanceClass(const Aws::String &engine, const Aws::String &engineVersion, Aws::String &dbInstanceClass, const Aws::RDS::RDSClient &client) { std::vector<Aws::String> instanceClasses; Aws::String marker; // The marker is used for pagination. do { Aws::RDS::Model::DescribeOrderableDBInstanceOptionsRequest request; request.SetEngine(engine); request.SetEngineVersion(engineVersion); if (!marker.empty()) { request.SetMarker(marker); } Aws::RDS::Model::DescribeOrderableDBInstanceOptionsOutcome outcome = client.DescribeOrderableDBInstanceOptions(request); if (outcome.IsSuccess()) { const Aws::Vector<Aws::RDS::Model::OrderableDBInstanceOption> &options = outcome.GetResult().GetOrderableDBInstanceOptions(); for (const Aws::RDS::Model::OrderableDBInstanceOption &option: options) { const Aws::String &instanceClass = option.GetDBInstanceClass(); if (std::find(instanceClasses.begin(), instanceClasses.end(), instanceClass) == instanceClasses.end()) { instanceClasses.push_back(instanceClass); } } marker = outcome.GetResult().GetMarker(); } else { std::cerr << "Error with Aurora::DescribeOrderableDBInstanceOptions. " << outcome.GetError().GetMessage() << std::endl; return false; } } while (!marker.empty()); std::cout << "The available DB instance classes for your database engine are:" << std::endl; for (int i = 0; i < instanceClasses.size(); ++i) { std::cout << " " << i + 1 << ": " << instanceClasses[i] << std::endl; } int choice = askQuestionForIntRange( "Which DB instance class do you want to use? ", 1, static_cast<int>(instanceClasses.size())); dbInstanceClass = instanceClasses[choice - 1]; return true; }
-
有关 API 详细信息,请参阅《AWS SDK for C++ API 参考》中的 DescribeOrderableDBInstanceOptions。
-
- Go
-
- 适用于 Go V2 的 SDK
-
注意
查看 GitHub,了解更多信息。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 type DbClusters struct { AuroraClient *rds.Client } // GetOrderableInstances uses a paginator to get DB instance options that can be used to create DB instances that are // compatible with a set of specifications. func (clusters *DbClusters) GetOrderableInstances(ctx context.Context, engine string, engineVersion string) ( []types.OrderableDBInstanceOption, error) { var output *rds.DescribeOrderableDBInstanceOptionsOutput var instances []types.OrderableDBInstanceOption var err error orderablePaginator := rds.NewDescribeOrderableDBInstanceOptionsPaginator(clusters.AuroraClient, &rds.DescribeOrderableDBInstanceOptionsInput{ Engine: aws.String(engine), EngineVersion: aws.String(engineVersion), }) for orderablePaginator.HasMorePages() { output, err = orderablePaginator.NextPage(ctx) if err != nil { log.Printf("Couldn't get orderable DB instances: %v\n", err) break } else { instances = append(instances, output.OrderableDBInstanceOptions...) } } return instances, err }
-
有关 API 详细信息,请参阅《AWS SDK for Go API 参考》中的 DescribeOrderableDBInstanceOptions
。
-
- Java
-
- SDK for Java 2.x
-
注意
查看 GitHub,了解更多信息。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 public static void describeDBEngines(RdsClient rdsClient) { try { DescribeDbEngineVersionsRequest engineVersionsRequest = DescribeDbEngineVersionsRequest.builder() .engine("aurora-mysql") .defaultOnly(true) .maxRecords(20) .build(); DescribeDbEngineVersionsResponse response = rdsClient.describeDBEngineVersions(engineVersionsRequest); List<DBEngineVersion> engines = response.dbEngineVersions(); // Get all DBEngineVersion objects. for (DBEngineVersion engineOb : engines) { System.out.println("The name of the DB parameter group family for the database engine is " + engineOb.dbParameterGroupFamily()); System.out.println("The name of the database engine " + engineOb.engine()); System.out.println("The version number of the database engine " + engineOb.engineVersion()); } } catch (RdsException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } }
-
有关 API 详细信息,请参阅《AWS SDK for Java 2.x API 参考》中的 DescribeOrderableDBInstanceOptions。
-
- PowerShell
-
- 适用于 PowerShell 的工具
-
示例 1:此示例列出了支持AWS 区域特定数据库实例类的数据库引擎版本。
$params = @{ Engine = 'aurora-postgresql' DBInstanceClass = 'db.r5.large' Region = 'us-east-1' } Get-RDSOrderableDBInstanceOption @params
示例 2:此示例列出了AWS 区域特定数据库引擎版本支持的数据库实例类。
$params = @{ Engine = 'aurora-postgresql' EngineVersion = '13.6' Region = 'us-east-1' } Get-RDSOrderableDBInstanceOption @params
-
有关 API 详细信息,请参阅《AWS Tools for PowerShell Cmdlet 参考》中的 DescribeOrderableDBInstanceOptions。
-
- Python
-
- SDK for Python (Boto3)
-
注意
查看 GitHub,了解更多信息。查找完整示例,学习如何在 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_orderable_instances(self, db_engine, db_engine_version): """ Gets DB instance options that can be used to create DB instances that are compatible with a set of specifications. :param db_engine: The database engine that must be supported by the DB instance. :param db_engine_version: The engine version that must be supported by the DB instance. :return: The list of DB instance options that can be used to create a compatible DB instance. """ try: inst_opts = [] paginator = self.rds_client.get_paginator( "describe_orderable_db_instance_options" ) for page in paginator.paginate( Engine=db_engine, EngineVersion=db_engine_version ): inst_opts += page["OrderableDBInstanceOptions"] except ClientError as err: logger.error( "Couldn't get orderable DB instances. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return inst_opts
-
有关 API 详细信息,请参阅《AWS SDK for Python (Boto3) API 参考》中的 DescribeOrderableDBInstanceOptions。
-
- Rust
-
- 适用于 Rust 的 SDK
-
注意
查看 GitHub,了解更多信息。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 pub async fn get_instance_classes(&self) -> Result<Vec<String>, ScenarioError> { let describe_orderable_db_instance_options_items = self .rds .describe_orderable_db_instance_options( DB_ENGINE, self.engine_version .as_ref() .expect("engine version for db instance options") .as_str(), ) .await; describe_orderable_db_instance_options_items .map(|options| { options .iter() .filter(|o| o.storage_type() == Some("aurora")) .map(|o| o.db_instance_class().unwrap_or_default().to_string()) .collect::<Vec<String>>() }) .map_err(|err| ScenarioError::new("Could not get available instance classes", &err)) } pub async fn describe_orderable_db_instance_options( &self, engine: &str, engine_version: &str, ) -> Result<Vec<OrderableDbInstanceOption>, SdkError<DescribeOrderableDBInstanceOptionsError>> { self.inner .describe_orderable_db_instance_options() .engine(engine) .engine_version(engine_version) .into_paginator() .items() .send() .try_collect() .await } #[tokio::test] async fn test_scenario_get_instance_classes() { let mut mock_rds = MockRdsImpl::default(); mock_rds .expect_create_db_cluster_parameter_group() .return_once(|_, _, _| { Ok(CreateDbClusterParameterGroupOutput::builder() .db_cluster_parameter_group(DbClusterParameterGroup::builder().build()) .build()) }); mock_rds .expect_describe_orderable_db_instance_options() .with(eq("aurora-mysql"), eq("aurora-mysql8.0")) .return_once(|_, _| { Ok(vec![ OrderableDbInstanceOption::builder() .db_instance_class("t1") .storage_type("aurora") .build(), OrderableDbInstanceOption::builder() .db_instance_class("t1") .storage_type("aurora-iopt1") .build(), OrderableDbInstanceOption::builder() .db_instance_class("t2") .storage_type("aurora") .build(), OrderableDbInstanceOption::builder() .db_instance_class("t3") .storage_type("aurora") .build(), ]) }); let mut scenario = AuroraScenario::new(mock_rds); scenario .set_engine("aurora-mysql", "aurora-mysql8.0") .await .expect("set engine"); let instance_classes = scenario.get_instance_classes().await; assert_eq!( instance_classes, Ok(vec!["t1".into(), "t2".into(), "t3".into()]) ); } #[tokio::test] async fn test_scenario_get_instance_classes_error() { let mut mock_rds = MockRdsImpl::default(); mock_rds .expect_describe_orderable_db_instance_options() .with(eq("aurora-mysql"), eq("aurora-mysql8.0")) .return_once(|_, _| { Err(SdkError::service_error( DescribeOrderableDBInstanceOptionsError::unhandled(Box::new(Error::new( ErrorKind::Other, "describe_orderable_db_instance_options_error", ))), Response::new(StatusCode::try_from(400).unwrap(), SdkBody::empty()), )) }); let mut scenario = AuroraScenario::new(mock_rds); scenario.engine_family = Some("aurora-mysql".into()); scenario.engine_version = Some("aurora-mysql8.0".into()); let instance_classes = scenario.get_instance_classes().await; assert_matches!( instance_classes, Err(ScenarioError {message, context: _}) if message == "Could not get available instance classes" ); }
-
有关 API 详细信息,请参阅《AWS SDK for Rust API 参考》中的 DescribeOrderableDBInstanceOptions
。
-
有关 AWS SDK 开发人员指南和代码示例的完整列表,请参阅 将此服务与 AWS SDK 结合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。