AWS SDK を使用して Amazon RDS DB パラメータグループを作成する - AWS SDK コードサンプル

Doc AWS SDK Examples リポジトリには、他にも SDK の例があります。 AWS GitHub

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS SDK を使用して Amazon RDS DB パラメータグループを作成する

次のコードサンプルは、Amazon RDS DB パラメータグループを作成する方法を示しています。

アクション例は、より大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。次のコード例で、このアクションのコンテキストを確認できます。

.NET
AWS SDK for .NET
注記

には他にもがあります GitHub。用例一覧を検索し、AWS コードサンプルリポジトリでの設定と実行の方法を確認してください。

/// <summary> /// Create a new DB parameter group. Use the action DescribeDBParameterGroupsAsync /// to determine when the DB parameter group is ready to use. /// </summary> /// <param name="name">Name of the DB parameter group.</param> /// <param name="family">Family of the DB parameter group.</param> /// <param name="description">Description of the DB parameter group.</param> /// <returns>The new DB parameter group.</returns> public async Task<DBParameterGroup> CreateDBParameterGroup( string name, string family, string description) { var response = await _amazonRDS.CreateDBParameterGroupAsync( new CreateDBParameterGroupRequest() { DBParameterGroupName = name, DBParameterGroupFamily = family, Description = description }); return response.DBParameterGroup; }
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); Aws::RDS::Model::CreateDBParameterGroupRequest request; request.SetDBParameterGroupName(PARAMETER_GROUP_NAME); request.SetDBParameterGroupFamily(dbParameterGroupFamily); request.SetDescription("Example parameter group."); Aws::RDS::Model::CreateDBParameterGroupOutcome outcome = client.CreateDBParameterGroup(request); if (outcome.IsSuccess()) { std::cout << "The DB parameter group was successfully created." << std::endl; } else { std::cerr << "Error with RDS::CreateDBParameterGroup. " << outcome.GetError().GetMessage() << std::endl; return false; }
CLI
AWS CLI

DB パラメータグループを作成するには

次の create-db-parameter-group の例は、DB パラメータグループを作成します。

aws rds create-db-parameter-group \ --db-parameter-group-name mydbparametergroup \ --db-parameter-group-family MySQL5.6 \ --description "My new parameter group"

出力:

{ "DBParameterGroup": { "DBParameterGroupName": "mydbparametergroup", "DBParameterGroupFamily": "mysql5.6", "Description": "My new parameter group", "DBParameterGroupArn": "arn:aws:rds:us-east-1:123456789012:pg:mydbparametergroup" } }

詳細については、「Amazon RDS ユーザーガイド」の「DB パラメータグループを作成する」を参照してください。

  • API の詳細については、AWS CLI「 コマンドリファレンス」の「CreateDBParameterGroup」を参照してください。

Go
SDK for Go V2
注記

には他にもがあります GitHub。用例一覧を検索し、AWS コードサンプルリポジトリでの設定と実行の方法を確認してください。

type DbInstances struct { RdsClient *rds.Client } // CreateParameterGroup creates a DB parameter group that is based on the specified // parameter group family. func (instances *DbInstances) CreateParameterGroup( parameterGroupName string, parameterGroupFamily string, description string) ( *types.DBParameterGroup, error) { output, err := instances.RdsClient.CreateDBParameterGroup(context.TODO(), &rds.CreateDBParameterGroupInput{ DBParameterGroupName: aws.String(parameterGroupName), DBParameterGroupFamily: aws.String(parameterGroupFamily), Description: aws.String(description), }) if err != nil { log.Printf("Couldn't create parameter group %v: %v\n", parameterGroupName, err) return nil, err } else { return output.DBParameterGroup, err } }
Java
SDK for Java 2.x
注記

には他にもがあります GitHub。用例一覧を検索し、AWS コードサンプルリポジトリでの設定と実行の方法を確認してください。

public static void createDBParameterGroup(RdsClient rdsClient, String dbGroupName, String dbParameterGroupFamily) { try { CreateDbParameterGroupRequest groupRequest = CreateDbParameterGroupRequest.builder() .dbParameterGroupName(dbGroupName) .dbParameterGroupFamily(dbParameterGroupFamily) .description("Created by using the AWS SDK for Java") .build(); CreateDbParameterGroupResponse response = rdsClient.createDBParameterGroup(groupRequest); System.out.println("The group name is " + response.dbParameterGroup().dbParameterGroupName()); } catch (RdsException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } }
Python
SDK for Python (Boto3)
注記

には他にもがあります 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 create_parameter_group( self, parameter_group_name, parameter_group_family, description ): """ Creates a DB parameter group that is based on the specified parameter group family. :param parameter_group_name: The name of the newly created parameter group. :param parameter_group_family: The family that is used as the basis of the new parameter group. :param description: A description given to the parameter group. :return: Data about the newly created parameter group. """ try: response = self.rds_client.create_db_parameter_group( DBParameterGroupName=parameter_group_name, DBParameterGroupFamily=parameter_group_family, Description=description, ) except ClientError as err: logger.error( "Couldn't create parameter group %s. Here's why: %s: %s", parameter_group_name, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return response