将 DescribeDBParameterGroups 与 Amazon SDK 或 CLI 配合使用 - Amazon Relational Database Service
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

DescribeDBParameterGroups 与 Amazon SDK 或 CLI 配合使用

以下代码示例演示如何使用 DescribeDBParameterGroups

操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:

.NET
Amazon SDK for .NET
注意

在 GitHub 上查看更多内容。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

/// <summary> /// Get descriptions of DB parameter groups. /// </summary> /// <param name="name">Optional name of the DB parameter group to describe.</param> /// <returns>The list of DB parameter group descriptions.</returns> public async Task<List<DBParameterGroup>> DescribeDBParameterGroups(string name = null) { var response = await _amazonRDS.DescribeDBParameterGroupsAsync( new DescribeDBParameterGroupsRequest() { DBParameterGroupName = name }); return response.DBParameterGroups; }
C++
适用于 C++ 的 SDK
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region (overrides config file). // clientConfig.region = "us-east-1"; Aws::RDS::RDSClient client(clientConfig); Aws::RDS::Model::DescribeDBParameterGroupsRequest request; request.SetDBParameterGroupName(PARAMETER_GROUP_NAME); Aws::RDS::Model::DescribeDBParameterGroupsOutcome outcome = client.DescribeDBParameterGroups(request); if (outcome.IsSuccess()) { std::cout << "DB parameter group named '" << PARAMETER_GROUP_NAME << "' already exists." << std::endl; dbParameterGroupFamily = outcome.GetResult().GetDBParameterGroups()[0].GetDBParameterGroupFamily(); } else { std::cerr << "Error with RDS::DescribeDBParameterGroups. " << outcome.GetError().GetMessage() << std::endl; return false; }
CLI
Amazon CLI

描述数据库参数组

以下 describe-db-parameter-groups 示例将检索有关数据库参数组的详细信息。

aws rds describe-db-parameter-groups

输出:

{ "DBParameterGroups": [ { "DBParameterGroupName": "default.aurora-mysql5.7", "DBParameterGroupFamily": "aurora-mysql5.7", "Description": "Default parameter group for aurora-mysql5.7", "DBParameterGroupArn": "arn:aws:rds:us-east-1:123456789012:pg:default.aurora-mysql5.7" }, { "DBParameterGroupName": "default.aurora-postgresql9.6", "DBParameterGroupFamily": "aurora-postgresql9.6", "Description": "Default parameter group for aurora-postgresql9.6", "DBParameterGroupArn": "arn:aws:rds:us-east-1:123456789012:pg:default.aurora-postgresql9.6" }, { "DBParameterGroupName": "default.aurora5.6", "DBParameterGroupFamily": "aurora5.6", "Description": "Default parameter group for aurora5.6", "DBParameterGroupArn": "arn:aws:rds:us-east-1:123456789012:pg:default.aurora5.6" }, { "DBParameterGroupName": "default.mariadb10.1", "DBParameterGroupFamily": "mariadb10.1", "Description": "Default parameter group for mariadb10.1", "DBParameterGroupArn": "arn:aws:rds:us-east-1:123456789012:pg:default.mariadb10.1" }, ...some output truncated... ] }

有关更多信息,请参阅《Amazon RDS 用户指南》中的使用数据库参数组

Go
适用于 Go V2 的 SDK
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

type DbInstances struct { RdsClient *rds.Client } // GetParameterGroup gets a DB parameter group by name. func (instances *DbInstances) GetParameterGroup(parameterGroupName string) ( *types.DBParameterGroup, error) { output, err := instances.RdsClient.DescribeDBParameterGroups( context.TODO(), &rds.DescribeDBParameterGroupsInput{ DBParameterGroupName: aws.String(parameterGroupName), }) if err != nil { var notFoundError *types.DBParameterGroupNotFoundFault if errors.As(err, &notFoundError) { log.Printf("Parameter group %v does not exist.\n", parameterGroupName) err = nil } else { log.Printf("Error getting parameter group %v: %v\n", parameterGroupName, err) } return nil, err } else { return &output.DBParameterGroups[0], err } }
Java
SDK for Java 2.x
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

public static void describeDbParameterGroups(RdsClient rdsClient, String dbGroupName) { try { DescribeDbParameterGroupsRequest groupsRequest = DescribeDbParameterGroupsRequest.builder() .dbParameterGroupName(dbGroupName) .maxRecords(20) .build(); DescribeDbParameterGroupsResponse response = rdsClient.describeDBParameterGroups(groupsRequest); List<DBParameterGroup> groups = response.dbParameterGroups(); for (DBParameterGroup group : groups) { System.out.println("The group name is " + group.dbParameterGroupName()); System.out.println("The group description is " + group.description()); } } catch (RdsException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } }
Python
SDK for Python(Boto3)
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

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_parameter_group(self, parameter_group_name): """ Gets a DB parameter group. :param parameter_group_name: The name of the parameter group to retrieve. :return: The parameter group. """ try: response = self.rds_client.describe_db_parameter_groups( DBParameterGroupName=parameter_group_name ) parameter_group = response["DBParameterGroups"][0] except ClientError as err: if err.response["Error"]["Code"] == "DBParameterGroupNotFound": logger.info("Parameter group %s does not exist.", parameter_group_name) else: logger.error( "Couldn't get parameter group %s. Here's why: %s: %s", parameter_group_name, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return parameter_group
  • 有关 API 详细信息,请参阅《适用于 Python 的 Amazon SDK(Boto3)API 参考》中的 DescribeDBParameterGroups

Ruby
适用于 Ruby 的 SDK
注意

查看 GitHub,了解更多信息。查找完整示例,学习如何在 Amazon 代码示例存储库中进行设置和运行。

require "aws-sdk-rds" # v2: require 'aws-sdk' # List all Amazon Relational Database Service (Amazon RDS) parameter groups. # # @param rds_resource [Aws::RDS::Resource] An SDK for Ruby Amazon RDS resource. # @return [Array, nil] List of all parameter groups, or nil if error. def list_parameter_groups(rds_resource) parameter_groups = [] rds_resource.db_parameter_groups.each do |p| parameter_groups.append({ "name": p.db_parameter_group_name, "description": p.description }) end parameter_groups rescue Aws::Errors::ServiceError => e puts "Couldn't list parameter groups:\n #{e.message}" end

有关 Amazon SDK 开发人员指南和代码示例的完整列表,请参阅 将此服务与 Amazon SDK 结合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。