Use ModifyDBClusterParameterGroup with an AWS SDK or CLI - Amazon Aurora

Use ModifyDBClusterParameterGroup with an AWS SDK or CLI

The following code examples show how to use ModifyDBClusterParameterGroup.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

.NET
AWS SDK for .NET
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

/// <summary> /// Modify the specified integer parameters with new values from user input. /// </summary> /// <param name="groupName">The group name for the parameters.</param> /// <param name="parameters">The list of integer parameters to modify.</param> /// <param name="newValue">Optional int value to set for parameters.</param> /// <returns>The name of the group that was modified.</returns> public async Task<string> ModifyIntegerParametersInGroupAsync(string groupName, List<Parameter> parameters, int newValue = 0) { foreach (var p in parameters) { if (p.IsModifiable && p.DataType == "integer") { while (newValue == 0) { Console.WriteLine( $"Enter a new value for {p.ParameterName} from the allowed values {p.AllowedValues} "); var choice = Console.ReadLine(); int.TryParse(choice, out newValue); } p.ParameterValue = newValue.ToString(); } } var request = new ModifyDBClusterParameterGroupRequest { Parameters = parameters, DBClusterParameterGroupName = groupName, }; var result = await _amazonRDS.ModifyDBClusterParameterGroupAsync(request); return result.DBClusterParameterGroupName; }
C++
SDK for C++
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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::ModifyDBClusterParameterGroupRequest request; request.SetDBClusterParameterGroupName(CLUSTER_PARAMETER_GROUP_NAME); request.SetParameters(updateParameters); Aws::RDS::Model::ModifyDBClusterParameterGroupOutcome outcome = client.ModifyDBClusterParameterGroup(request); if (outcome.IsSuccess()) { std::cout << "The DB cluster parameter group was successfully modified." << std::endl; } else { std::cerr << "Error with Aurora::ModifyDBClusterParameterGroup. " << outcome.GetError().GetMessage() << std::endl; }
Go
SDK for Go V2
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

type DbClusters struct { AuroraClient *rds.Client } // UpdateParameters updates parameters in a named DB cluster parameter group. func (clusters *DbClusters) UpdateParameters(parameterGroupName string, params []types.Parameter) error { _, err := clusters.AuroraClient.ModifyDBClusterParameterGroup(context.TODO(), &rds.ModifyDBClusterParameterGroupInput{ DBClusterParameterGroupName: aws.String(parameterGroupName), Parameters: params, }) if err != nil { log.Printf("Couldn't update parameters in %v: %v\n", parameterGroupName, err) return err } else { return nil } }
Java
SDK for Java 2.x
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

public static void describeDbClusterParameterGroups(RdsClient rdsClient, String dbClusterGroupName) { try { DescribeDbClusterParameterGroupsRequest groupsRequest = DescribeDbClusterParameterGroupsRequest.builder() .dbClusterParameterGroupName(dbClusterGroupName) .maxRecords(20) .build(); List<DBClusterParameterGroup> groups = rdsClient.describeDBClusterParameterGroups(groupsRequest) .dbClusterParameterGroups(); for (DBClusterParameterGroup group : groups) { System.out.println("The group name is " + group.dbClusterParameterGroupName()); System.out.println("The group ARN is " + group.dbClusterParameterGroupArn()); } } catch (RdsException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } }
Kotlin
SDK for Kotlin
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

// Modify the auto_increment_offset parameter. suspend fun modifyDBClusterParas(dClusterGroupName: String?) { val parameter1 = Parameter { parameterName = "auto_increment_offset" applyMethod = ApplyMethod.fromValue("immediate") parameterValue = "5" } val paraList = ArrayList<Parameter>() paraList.add(parameter1) val groupRequest = ModifyDbClusterParameterGroupRequest { dbClusterParameterGroupName = dClusterGroupName parameters = paraList } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.modifyDbClusterParameterGroup(groupRequest) println("The parameter group ${response.dbClusterParameterGroupName} was successfully modified") } }
Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

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 update_parameters(self, parameter_group_name, update_parameters): """ Updates parameters in a custom DB cluster parameter group. :param parameter_group_name: The name of the parameter group to update. :param update_parameters: The parameters to update in the group. :return: Data about the modified parameter group. """ try: response = self.rds_client.modify_db_cluster_parameter_group( DBClusterParameterGroupName=parameter_group_name, Parameters=update_parameters, ) except ClientError as err: logger.error( "Couldn't update parameters in %s. Here's why: %s: %s", parameter_group_name, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return response
Rust
SDK for Rust
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

// Modify both the auto_increment_offset and auto_increment_increment parameters in one call in the custom parameter group. Set their ParameterValue fields to a new allowable value. rds.ModifyDbClusterParameterGroup. pub async fn update_auto_increment( &self, offset: u8, increment: u8, ) -> Result<(), ScenarioError> { let modify_db_cluster_parameter_group = self .rds .modify_db_cluster_parameter_group( DB_CLUSTER_PARAMETER_GROUP_NAME, vec![ Parameter::builder() .parameter_name("auto_increment_offset") .parameter_value(format!("{offset}")) .apply_method(aws_sdk_rds::types::ApplyMethod::Immediate) .build(), Parameter::builder() .parameter_name("auto_increment_increment") .parameter_value(format!("{increment}")) .apply_method(aws_sdk_rds::types::ApplyMethod::Immediate) .build(), ], ) .await; if let Err(error) = modify_db_cluster_parameter_group { return Err(ScenarioError::new( "Failed to modify cluster parameter group", &error, )); } Ok(()) } pub async fn modify_db_cluster_parameter_group( &self, name: &str, parameters: Vec<Parameter>, ) -> Result<ModifyDbClusterParameterGroupOutput, SdkError<ModifyDBClusterParameterGroupError>> { self.inner .modify_db_cluster_parameter_group() .db_cluster_parameter_group_name(name) .set_parameters(Some(parameters)) .send() .await } #[tokio::test] async fn test_scenario_update_auto_increment() { let mut mock_rds = MockRdsImpl::default(); mock_rds .expect_modify_db_cluster_parameter_group() .withf(|name, params| { assert_eq!(name, "RustSDKCodeExamplesDBParameterGroup"); assert_eq!( params, &vec![ Parameter::builder() .parameter_name("auto_increment_offset") .parameter_value("10") .apply_method(aws_sdk_rds::types::ApplyMethod::Immediate) .build(), Parameter::builder() .parameter_name("auto_increment_increment") .parameter_value("20") .apply_method(aws_sdk_rds::types::ApplyMethod::Immediate) .build(), ] ); true }) .return_once(|_, _| Ok(ModifyDbClusterParameterGroupOutput::builder().build())); let scenario = AuroraScenario::new(mock_rds); scenario .update_auto_increment(10, 20) .await .expect("update auto increment"); } #[tokio::test] async fn test_scenario_update_auto_increment_error() { let mut mock_rds = MockRdsImpl::default(); mock_rds .expect_modify_db_cluster_parameter_group() .return_once(|_, _| { Err(SdkError::service_error( ModifyDBClusterParameterGroupError::unhandled(Box::new(Error::new( ErrorKind::Other, "modify_db_cluster_parameter_group_error", ))), Response::new(StatusCode::try_from(400).unwrap(), SdkBody::empty()), )) }); let scenario = AuroraScenario::new(mock_rds); let update = scenario.update_auto_increment(10, 20).await; assert_matches!(update, Err(ScenarioError { message, context: _}) if message == "Failed to modify cluster parameter group"); }

For a complete list of AWS SDK developer guides and code examples, see Using this service with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.