Create an Aurora DB cluster using an Amazon SDK
The following code examples show how to create an Aurora DB cluster.
- .NET
-
- Amazon SDK for .NET
-
Note There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository
. /// <summary> /// Create a new cluster and database. /// </summary> /// <param name="dbName">The name of the new database.</param> /// <param name="clusterIdentifier">The identifier of the cluster.</param> /// <param name="parameterGroupName">The name of the parameter group.</param> /// <param name="dbEngine">The engine to use for the new cluster.</param> /// <param name="dbEngineVersion">The version of the engine to use.</param> /// <param name="adminName">The admin username.</param> /// <param name="adminPassword">The primary admin password.</param> /// <returns>The cluster object.</returns> public async Task<DBCluster> CreateDBClusterWithAdminAsync( string dbName, string clusterIdentifier, string parameterGroupName, string dbEngine, string dbEngineVersion, string adminName, string adminPassword) { var request = new CreateDBClusterRequest { DatabaseName = dbName, DBClusterIdentifier = clusterIdentifier, DBClusterParameterGroupName = parameterGroupName, Engine = dbEngine, EngineVersion = dbEngineVersion, MasterUsername = adminName, MasterUserPassword = adminPassword, }; var response = await _amazonRDS.CreateDBClusterAsync(request); return response.DBCluster; }
-
For API details, see CreateDBCluster in Amazon SDK for .NET API Reference.
-
- C++
-
- SDK for C++
-
Note There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon 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::CreateDBClusterRequest request; request.SetDBClusterIdentifier(DB_CLUSTER_IDENTIFIER); request.SetDBClusterParameterGroupName(CLUSTER_PARAMETER_GROUP_NAME); request.SetEngine(engineName); request.SetEngineVersion(engineVersionName); request.SetMasterUsername(administratorName); request.SetMasterUserPassword(administratorPassword); Aws::RDS::Model::CreateDBClusterOutcome outcome = client.CreateDBCluster(request); if (outcome.IsSuccess()) { std::cout << "The DB cluster creation has started." << std::endl; } else { std::cerr << "Error with Aurora::CreateDBCluster. " << outcome.GetError().GetMessage() << std::endl; cleanUpResources(CLUSTER_PARAMETER_GROUP_NAME, "", "", client); return false; }
-
For API details, see CreateDBCluster in Amazon SDK for C++ API Reference.
-
- 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 Amazon Code Examples Repository
. public static String createDBCluster(RdsClient rdsClient, String dbParameterGroupFamily, String dbName, String dbClusterIdentifier, String userName, String password) { try { CreateDbClusterRequest clusterRequest = CreateDbClusterRequest.builder() .databaseName(dbName) .dbClusterIdentifier(dbClusterIdentifier) .dbClusterParameterGroupName(dbParameterGroupFamily) .engine("aurora-mysql") .masterUsername(userName) .masterUserPassword(password) .build(); CreateDbClusterResponse response = rdsClient.createDBCluster(clusterRequest); return response.dbCluster().dbClusterArn(); } catch (RdsException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } return ""; }
-
For API details, see CreateDBCluster in Amazon SDK for Java 2.x API Reference.
-
- Kotlin
-
- SDK for Kotlin
-
Note This is prerelease documentation for a feature in preview release. It is subject to change.
Note There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository
. suspend fun createDBCluster(dbParameterGroupFamilyVal: String?, dbName: String?, dbClusterIdentifierVal: String?, userName: String?, password: String?): String? { val clusterRequest = CreateDbClusterRequest { databaseName = dbName dbClusterIdentifier = dbClusterIdentifierVal dbClusterParameterGroupName = dbParameterGroupFamilyVal engine = "aurora-mysql" masterUsername = userName masterUserPassword = password } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.createDbCluster(clusterRequest) return response.dbCluster?.dbClusterArn } }
-
For API details, see CreateDBCluster
in Amazon SDK for Kotlin API reference.
-
- 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 Amazon 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 create_db_cluster( self, cluster_name, parameter_group_name, db_name, db_engine, db_engine_version, admin_name, admin_password): """ Creates a DB cluster that is configured to use the specified parameter group. The newly created DB cluster contains a database that uses the specified engine and engine version. :param cluster_name: The name of the DB cluster to create. :param parameter_group_name: The name of the parameter group to associate with the DB cluster. :param db_name: The name of the database to create. :param db_engine: The database engine of the database that is created, such as MySql. :param db_engine_version: The version of the database engine. :param admin_name: The user name of the database administrator. :param admin_password: The password of the database administrator. :return: The newly created DB cluster. """ try: response = self.rds_client.create_db_cluster( DatabaseName=db_name, DBClusterIdentifier=cluster_name, DBClusterParameterGroupName=parameter_group_name, Engine=db_engine, EngineVersion=db_engine_version, MasterUsername=admin_name, MasterUserPassword=admin_password) cluster = response['DBCluster'] except ClientError as err: logger.error( "Couldn't create database %s. Here's why: %s: %s", db_name, err.response['Error']['Code'], err.response['Error']['Message']) raise else: return cluster
-
For API details, see CreateDBCluster in Amazon SDK for Python (Boto3) API Reference.
-
For a complete list of Amazon SDK developer guides and code examples, see Using this service with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.