文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
DescribeDBEngineVersions
搭配 a AWS SDK 或 CLI 使用
下列程式碼範例示範如何使用 DescribeDBEngineVersions
。
動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:
- .NET
-
- AWS SDK for .NET
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 /// <summary> /// Get a list of DB engine versions for a particular DB engine. /// </summary> /// <param name="engine">Name of the engine.</param> /// <param name="dbParameterGroupFamily">Optional parameter group family name.</param> /// <returns>List of DBEngineVersions.</returns> public async Task<List<DBEngineVersion>> DescribeDBEngineVersions(string engine, string dbParameterGroupFamily = null) { var response = await _amazonRDS.DescribeDBEngineVersionsAsync( new DescribeDBEngineVersionsRequest() { Engine = engine, DBParameterGroupFamily = dbParameterGroupFamily }); return response.DBEngineVersions; }
-
如需 API 詳細資訊,請參閱 Word 參考中的 DescribeDBEngine 版本。 AWS SDK for .NET API
-
- C++
-
- C++ 的 SDK
-
注意
還有更多 on 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 engine versions for an engine name and //! an optional parameter group family. /*! \sa getDBEngineVersions() \param engineName: A DB engine name. \param parameterGroupFamily: A parameter group family name, ignored if empty. \param engineVersionsResult: Vector of 'DBEngineVersion' objects returned by the routine. \param client: 'RDSClient' instance. \return bool: Successful completion. */ bool AwsDoc::RDS::getDBEngineVersions(const Aws::String &engineName, const Aws::String ¶meterGroupFamily, Aws::Vector<Aws::RDS::Model::DBEngineVersion> &engineVersionsResult, const Aws::RDS::RDSClient &client) { Aws::RDS::Model::DescribeDBEngineVersionsRequest request; request.SetEngine(engineName); if (!parameterGroupFamily.empty()) { request.SetDBParameterGroupFamily(parameterGroupFamily); } engineVersionsResult.clear(); Aws::String marker; // Used for pagination. do { if (!marker.empty()) { request.SetMarker(marker); } Aws::RDS::Model::DescribeDBEngineVersionsOutcome outcome = client.DescribeDBEngineVersions(request); if (outcome.IsSuccess()) { auto &engineVersions = outcome.GetResult().GetDBEngineVersions(); engineVersionsResult.insert(engineVersionsResult.end(), engineVersions.begin(), engineVersions.end()); marker = outcome.GetResult().GetMarker(); } else { std::cerr << "Error with RDS::DescribeDBEngineVersionsRequest. " << outcome.GetError().GetMessage() << std::endl; return false; } } while (!marker.empty()); return true; }
-
如需 API 詳細資訊,請參閱 Word 參考中的 DescribeDBEngine 版本。 AWS SDK for C++ API
-
- CLI
-
- AWS CLI
-
描述 MySQL 資料庫引擎的資料庫引擎版本
下列
describe-db-engine-versions
範例顯示指定資料庫引擎的每個資料庫引擎版本的詳細資訊。aws rds describe-db-engine-versions \ --engine
mysql
輸出:
{ "DBEngineVersions": [ { "Engine": "mysql", "EngineVersion": "5.5.46", "DBParameterGroupFamily": "mysql5.5", "DBEngineDescription": "MySQL Community Edition", "DBEngineVersionDescription": "MySQL 5.5.46", "ValidUpgradeTarget": [ { "Engine": "mysql", "EngineVersion": "5.5.53", "Description": "MySQL 5.5.53", "AutoUpgrade": false, "IsMajorVersionUpgrade": false }, { "Engine": "mysql", "EngineVersion": "5.5.54", "Description": "MySQL 5.5.54", "AutoUpgrade": false, "IsMajorVersionUpgrade": false }, { "Engine": "mysql", "EngineVersion": "5.5.57", "Description": "MySQL 5.5.57", "AutoUpgrade": false, "IsMajorVersionUpgrade": false }, ...some output truncated... ] }
如需詳細資訊,請參閱 Amazon RDSWord 使用者指南中的什麼是 Amazon Relational Database Service (Amazon Word)?。 RDS
-
如需 API 詳細資訊,請參閱 AWS CLI 命令參考中的 DescribeDBEngine 版本
。
-
- Go
-
- SDK for Go V2
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 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 DbInstances struct { RdsClient *rds.Client } // GetEngineVersions gets database engine versions that are available for the specified engine // and parameter group family. func (instances *DbInstances) GetEngineVersions(ctx context.Context, engine string, parameterGroupFamily string) ( []types.DBEngineVersion, error) { output, err := instances.RdsClient.DescribeDBEngineVersions(ctx, &rds.DescribeDBEngineVersionsInput{ Engine: aws.String(engine), DBParameterGroupFamily: aws.String(parameterGroupFamily), }) if err != nil { log.Printf("Couldn't get engine versions for %v: %v\n", engine, err) return nil, err } else { return output.DBEngineVersions, nil } }
-
如需 API 詳細資訊,請參閱 Word 參考中的 DescribeDBEngine 版本
。 AWS SDK for Go API
-
- Java
-
- Java 2.x 的 SDK
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 public static void describeDBEngines(RdsClient rdsClient) { try { DescribeDbEngineVersionsRequest engineVersionsRequest = DescribeDbEngineVersionsRequest.builder() .defaultOnly(true) .engine("mysql") .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 詳細資訊,請參閱 Word 參考中的 DescribeDBEngine 版本。 AWS SDK for Java 2.x API
-
- Python
-
- SDK for Python (Boto3)
-
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 class InstanceWrapper: """Encapsulates Amazon RDS DB instance actions.""" def __init__(self, rds_client): """ :param rds_client: A Boto3 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_engine_versions(self, engine, parameter_group_family=None): """ Gets database engine versions that are available for the specified engine and parameter group family. :param engine: The database engine to look up. :param parameter_group_family: When specified, restricts the returned list of engine versions to those that are compatible with this parameter group family. :return: The list of database engine versions. """ try: kwargs = {"Engine": engine} if parameter_group_family is not None: kwargs["DBParameterGroupFamily"] = parameter_group_family response = self.rds_client.describe_db_engine_versions(**kwargs) versions = response["DBEngineVersions"] except ClientError as err: logger.error( "Couldn't get engine versions for %s. Here's why: %s: %s", engine, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return versions
-
如需 API 詳細資訊,請參閱 escribeDBEngineWord for Python (Boto3) Word 參考中的 DWord 版本。 AWS SDK API
-