There are more AWS SDK examples available in the AWS Doc SDK Examples
Aurora examples using SDK for .NET (v4)
The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for .NET (v4) with Aurora.
Basics are code examples that show you how to perform the essential operations within a service.
Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios.
Each example includes a link to the complete source code, where you can find instructions on how to set up and run the code in context.
Topics
Get started
The following code example shows how to get started using Aurora.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. using Amazon.RDS; using Amazon.RDS.Model; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; namespace AuroraActions; public static class HelloAurora { static async Task Main(string[] args) { // Use the AWS .NET Core Setup package to set up dependency injection for the // Amazon Relational Database Service (Amazon RDS). // Use your AWS profile name, or leave it blank to use the default profile. using var host = Host.CreateDefaultBuilder(args) .ConfigureServices((_, services) => services.AddAWSService() ).Build(); // Now the client is available for injection. Fetching it directly here for example purposes only. var rdsClient = host.Services.GetRequiredService (); // You can use await and any of the async methods to get a response. var response = await rdsClient.DescribeDBClustersAsync(new DescribeDBClustersRequest { IncludeShared = true }); Console.WriteLine($"Hello Amazon RDS Aurora! Let's list some clusters in this account:"); if (response.DBClusters == null) { Console.WriteLine($"\tNo clusters found."); } else { foreach (var cluster in response.DBClusters) { Console.WriteLine( $"\tCluster: database: {cluster.DatabaseName} identifier: {cluster.DBClusterIdentifier}."); } } } } -
For API details, see DescribeDBClusters in AWS SDK for .NET API Reference.
-
Basics
The following code example shows how to:
Create a custom Aurora DB cluster parameter group and set parameter values.
Create a DB cluster that uses the parameter group.
Create a DB instance that contains a database.
Take a snapshot of the DB cluster, then clean up resources.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. Run an interactive scenario at a command prompt.
using Amazon.RDS; using Amazon.RDS.Model; using AuroraActions; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Console; using Microsoft.Extensions.Logging.Debug; namespace AuroraScenario; ////// Scenario for Amazon Aurora examples. /// public class AuroraScenario { /* Before running this .NET code example, set up your development environment, including your credentials. This .NET example performs the following tasks: 1. Return a list of the available DB engine families for Aurora MySql using the DescribeDBEngineVersionsAsync method. 2. Select an engine family and create a custom DB cluster parameter group using the CreateDBClusterParameterGroupAsync method. 3. Get the parameter group using the DescribeDBClusterParameterGroupsAsync method. 4. Get some parameters in the group using the DescribeDBClusterParametersAsync method. 5. Parse and display some parameters in the group. 6. Modify the auto_increment_offset and auto_increment_increment parameters using the ModifyDBClusterParameterGroupAsync method. 7. Get and display the updated parameters using the DescribeDBClusterParametersAsync method with a source of "user". 8. Get a list of allowed engine versions using the DescribeDBEngineVersionsAsync method. 9. Create an Aurora DB cluster that contains a MySql database and uses the parameter group. using the CreateDBClusterAsync method. 10. Wait for the DB cluster to be ready using the DescribeDBClustersAsync method. 11. Display and select from a list of instance classes available for the selected engine and version using the paginated DescribeOrderableDBInstanceOptions method. 12. Create a database instance in the cluster using the CreateDBInstanceAsync method. 13. Wait for the DB instance to be ready using the DescribeDBInstances method. 14. Display the connection endpoint string for the new DB cluster. 15. Create a snapshot of the DB cluster using the CreateDBClusterSnapshotAsync method. 16. Wait for DB snapshot to be ready using the DescribeDBClusterSnapshotsAsync method. 17. Delete the DB instance using the DeleteDBInstanceAsync method. 18. Delete the DB cluster using the DeleteDBClusterAsync method. 19. Wait for DB cluster to be deleted using the DescribeDBClustersAsync methods. 20. Delete the cluster parameter group using the DeleteDBClusterParameterGroupAsync. */ private static readonly string sepBar = new('-', 80); private static AuroraWrapper auroraWrapper = null!; private static ILogger logger = null!; private static readonly string engine = "aurora-mysql"; static async Task Main(string[] args) { // Set up dependency injection for the Amazon Relational Database Service (Amazon RDS). using var host = Host.CreateDefaultBuilder(args) .ConfigureLogging(logging => logging.AddFilter("System", LogLevel.Debug) .AddFilter("Microsoft", LogLevel.Information) .AddFilter ("Microsoft", LogLevel.Trace)) .ConfigureServices((_, services) => services.AddAWSService () .AddTransient () ) .Build(); logger = LoggerFactory.Create(builder => { builder.AddConsole(); }).CreateLogger (); auroraWrapper = host.Services.GetRequiredService (); Console.WriteLine(sepBar); Console.WriteLine( "Welcome to the Amazon Aurora: get started with DB clusters example."); Console.WriteLine(sepBar); DBClusterParameterGroup parameterGroup = null!; DBCluster? newCluster = null; DBInstance? newInstance = null; try { var parameterGroupFamily = await ChooseParameterGroupFamilyAsync(); parameterGroup = await CreateDBParameterGroupAsync(parameterGroupFamily); var parameters = await DescribeParametersInGroupAsync(parameterGroup.DBClusterParameterGroupName, new List { "auto_increment_offset", "auto_increment_increment" }); await ModifyParametersAsync(parameterGroup.DBClusterParameterGroupName, parameters); await DescribeUserSourceParameters(parameterGroup.DBClusterParameterGroupName); var engineVersionChoice = await ChooseDBEngineVersionAsync(parameterGroupFamily); var newClusterIdentifier = "Example-Cluster-" + DateTime.Now.Ticks; newCluster = await CreateNewCluster ( parameterGroup, engine, engineVersionChoice.EngineVersion, newClusterIdentifier ); var instanceClassChoice = await ChooseDBInstanceClass(engine, engineVersionChoice.EngineVersion); var newInstanceIdentifier = "Example-Instance-" + DateTime.Now.Ticks; newInstance = await CreateNewInstance( newClusterIdentifier, engine, engineVersionChoice.EngineVersion, instanceClassChoice.DBInstanceClass, newInstanceIdentifier ); DisplayConnectionString(newCluster!); await CreateSnapshot(newCluster!); await CleanupResources(newInstance, newCluster, parameterGroup); Console.WriteLine("Scenario complete."); Console.WriteLine(sepBar); } catch (Exception ex) { await CleanupResources(newInstance, newCluster, parameterGroup); logger.LogError(ex, "There was a problem executing the scenario."); } } /// /// Choose the Aurora DB parameter group family from a list of available options. /// ///The selected parameter group family. public static async TaskChooseParameterGroupFamilyAsync() { Console.WriteLine(sepBar); // 1. Get a list of available engines. var engines = await auroraWrapper.DescribeDBEngineVersionsForEngineAsync(engine); Console.WriteLine($"1. The following is a list of available DB parameter group families for engine {engine}:"); var parameterGroupFamilies = engines.GroupBy(e => e.DBParameterGroupFamily).ToList(); for (var i = 1; i <= parameterGroupFamilies.Count; i++) { var parameterGroupFamily = parameterGroupFamilies[i - 1]; // List the available parameter group families. Console.WriteLine( $"\t{i}. Family: {parameterGroupFamily.Key}"); } var choiceNumber = 0; while (choiceNumber < 1 || choiceNumber > parameterGroupFamilies.Count) { Console.WriteLine("2. Select an available DB parameter group family by entering a number from the preceding list:"); var choice = Console.ReadLine(); Int32.TryParse(choice, out choiceNumber); } var parameterGroupFamilyChoice = parameterGroupFamilies[choiceNumber - 1]; Console.WriteLine(sepBar); return parameterGroupFamilyChoice.Key; } /// /// Create and get information on a DB parameter group. /// /// The DBParameterGroupFamily for the new DB parameter group. ///The new DBParameterGroup. public static async TaskCreateDBParameterGroupAsync(string dbParameterGroupFamily) { Console.WriteLine(sepBar); Console.WriteLine($"2. Create new DB parameter group with family {dbParameterGroupFamily}:"); var parameterGroup = await auroraWrapper.CreateCustomClusterParameterGroupAsync( dbParameterGroupFamily, "ExampleParameterGroup-" + DateTime.Now.Ticks, "New example parameter group"); var groupInfo = await auroraWrapper.DescribeCustomDBClusterParameterGroupAsync(parameterGroup.DBClusterParameterGroupName); Console.WriteLine( $"3. New DB parameter group created: \n\t{groupInfo?.Description}, \n\tARN {groupInfo?.DBClusterParameterGroupName}"); Console.WriteLine(sepBar); return parameterGroup; } /// /// Get and describe parameters from a DBParameterGroup. /// /// The name of the DBParameterGroup. /// Optional specific names of parameters to describe. ///The list of requested parameters. public static async Task- > DescribeParametersInGroupAsync(string parameterGroupName, List
? parameterNames = null) { Console.WriteLine(sepBar); Console.WriteLine("4. Get some parameters from the group."); Console.WriteLine(sepBar); var parameters = await auroraWrapper.DescribeDBClusterParametersInGroupAsync(parameterGroupName); var matchingParameters = parameters.Where(p => parameterNames == null || parameterNames.Contains(p.ParameterName)).ToList(); Console.WriteLine("5. Parameter information:"); matchingParameters.ForEach(p => Console.WriteLine( $"\n\tParameter: {p.ParameterName}." + $"\n\tDescription: {p.Description}." + $"\n\tAllowed Values: {p.AllowedValues}." + $"\n\tValue: {p.ParameterValue}.")); Console.WriteLine(sepBar); return matchingParameters; } /// /// Modify a parameter from a DBParameterGroup. /// /// Name of the DBParameterGroup. /// The parameters to modify. ///Async task. public static async Task ModifyParametersAsync(string parameterGroupName, Listparameters) { Console.WriteLine(sepBar); Console.WriteLine("6. Modify some parameters in the group."); await auroraWrapper.ModifyIntegerParametersInGroupAsync(parameterGroupName, parameters); Console.WriteLine(sepBar); } /// /// Describe the user source parameters in the group. /// /// The name of the DBParameterGroup. ///Async task. public static async Task DescribeUserSourceParameters(string parameterGroupName) { Console.WriteLine(sepBar); Console.WriteLine("7. Describe updated user source parameters in the group."); var parameters = await auroraWrapper.DescribeDBClusterParametersInGroupAsync(parameterGroupName, "user"); parameters.ForEach(p => Console.WriteLine( $"\n\tParameter: {p.ParameterName}." + $"\n\tDescription: {p.Description}." + $"\n\tAllowed Values: {p.AllowedValues}." + $"\n\tValue: {p.ParameterValue}.")); Console.WriteLine(sepBar); } ////// Choose a DB engine version. /// /// DB parameter group family for engine choice. ///The selected engine version. public static async TaskChooseDBEngineVersionAsync(string dbParameterGroupFamily) { Console.WriteLine(sepBar); // Get a list of allowed engines. var allowedEngines = await auroraWrapper.DescribeDBEngineVersionsForEngineAsync(engine, dbParameterGroupFamily); Console.WriteLine($"Available DB engine versions for parameter group family {dbParameterGroupFamily}:"); int i = 1; foreach (var version in allowedEngines) { Console.WriteLine( $"\t{i}. {version.DBEngineVersionDescription}."); i++; } var choiceNumber = 0; while (choiceNumber < 1 || choiceNumber > allowedEngines.Count) { Console.WriteLine("8. Select an available DB engine version by entering a number from the list above:"); var choice = Console.ReadLine(); Int32.TryParse(choice, out choiceNumber); } var engineChoice = allowedEngines[choiceNumber - 1]; Console.WriteLine(sepBar); return engineChoice; } /// /// Create a new RDS DB cluster. /// /// Parameter group to use for the DB cluster. /// Engine to use for the DB cluster. /// Engine version to use for the DB cluster. /// Cluster identifier to use for the DB cluster. ///The new DB cluster. public static async TaskCreateNewCluster(DBClusterParameterGroup parameterGroup, string engineName, string engineVersion, string clusterIdentifier) { Console.WriteLine(sepBar); Console.WriteLine($"9. Create a new DB cluster with identifier {clusterIdentifier}."); DBCluster newCluster; var clusters = await auroraWrapper.DescribeDBClustersPagedAsync(); var isClusterCreated = clusters.Any(i => i.DBClusterIdentifier == clusterIdentifier); if (isClusterCreated) { Console.WriteLine("Cluster already created."); newCluster = clusters.First(i => i.DBClusterIdentifier == clusterIdentifier); } else { Console.WriteLine("Enter an admin username:"); var username = Console.ReadLine(); Console.WriteLine("Enter an admin password:"); var password = Console.ReadLine(); newCluster = await auroraWrapper.CreateDBClusterWithAdminAsync( "ExampleDatabase", clusterIdentifier, parameterGroup.DBClusterParameterGroupName, engineName, engineVersion, username!, password! ); Console.WriteLine("10. Waiting for DB cluster to be ready..."); while (newCluster.Status != "available") { Console.Write("."); Thread.Sleep(5000); clusters = await auroraWrapper.DescribeDBClustersPagedAsync(clusterIdentifier); newCluster = clusters.First(); } } Console.WriteLine(sepBar); return newCluster; } /// /// Choose a DB instance class for a particular engine and engine version. /// /// DB engine for DB instance choice. /// DB engine version for DB instance choice. ///The selected orderable DB instance option. public static async TaskChooseDBInstanceClass(string engine, string engineVersion) { Console.WriteLine(sepBar); // Get a list of allowed DB instance classes. var allowedInstances = await auroraWrapper.DescribeOrderableDBInstanceOptionsPagedAsync(engine, engineVersion); Console.WriteLine($"Available DB instance classes for engine {engine} and version {engineVersion}:"); int i = 1; foreach (var instance in allowedInstances) { Console.WriteLine( $"\t{i}. Instance class: {instance.DBInstanceClass} (storage type {instance.StorageType})"); i++; } var choiceNumber = 0; while (choiceNumber < 1 || choiceNumber > allowedInstances.Count) { Console.WriteLine("11. Select an available DB instance class by entering a number from the preceding list:"); var choice = Console.ReadLine(); Int32.TryParse(choice, out choiceNumber); } var instanceChoice = allowedInstances[choiceNumber - 1]; Console.WriteLine(sepBar); return instanceChoice; } /// /// Create a new DB instance. /// /// Engine to use for the DB instance. /// Engine version to use for the DB instance. /// Instance class to use for the DB instance. /// Instance identifier to use for the DB instance. ///The new DB instance. public static async TaskCreateNewInstance( string clusterIdentifier, string engineName, string engineVersion, string instanceClass, string instanceIdentifier) { Console.WriteLine(sepBar); Console.WriteLine($"12. Create a new DB instance with identifier {instanceIdentifier}."); bool isInstanceReady = false; DBInstance newInstance; var instances = await auroraWrapper.DescribeDBInstancesPagedAsync(); isInstanceReady = instances.FirstOrDefault(i => i.DBInstanceIdentifier == instanceIdentifier)?.DBInstanceStatus == "available"; if (isInstanceReady) { Console.WriteLine("Instance already created."); newInstance = instances.First(i => i.DBInstanceIdentifier == instanceIdentifier); } else { newInstance = await auroraWrapper.CreateDBInstanceInClusterAsync( clusterIdentifier, instanceIdentifier, engineName, engineVersion, instanceClass ); Console.WriteLine("13. Waiting for DB instance to be ready..."); while (!isInstanceReady) { Console.Write("."); Thread.Sleep(5000); instances = await auroraWrapper.DescribeDBInstancesPagedAsync(instanceIdentifier); isInstanceReady = instances.FirstOrDefault()?.DBInstanceStatus == "available"; newInstance = instances.First(); } } Console.WriteLine(sepBar); return newInstance; } /// /// Display a connection string for an Amazon RDS DB cluster. /// /// The DB cluster to use to get a connection string. public static void DisplayConnectionString(DBCluster cluster) { Console.WriteLine(sepBar); // Display the connection string. Console.WriteLine("14. New DB cluster connection string: "); Console.WriteLine( $"\n{engine} -h {cluster.Endpoint} -P {cluster.Port} " + $"-u {cluster.MasterUsername} -p [YOUR PASSWORD]\n"); Console.WriteLine(sepBar); } ////// Create a snapshot from an Amazon RDS DB cluster. /// /// DB cluster to use when creating a snapshot. ///The snapshot object. public static async TaskCreateSnapshot(DBCluster cluster) { Console.WriteLine(sepBar); // Create a snapshot. Console.WriteLine($"15. Creating snapshot from DB cluster {cluster.DBClusterIdentifier}."); var snapshot = await auroraWrapper.CreateClusterSnapshotByIdentifierAsync( cluster.DBClusterIdentifier, "ExampleSnapshot-" + DateTime.Now.Ticks); // Wait for the snapshot to be available. bool isSnapshotReady = false; Console.WriteLine($"16. Waiting for snapshot to be ready..."); while (!isSnapshotReady) { Console.Write("."); Thread.Sleep(5000); var snapshots = await auroraWrapper.DescribeDBClusterSnapshotsByIdentifierAsync(cluster.DBClusterIdentifier); isSnapshotReady = snapshots.FirstOrDefault()?.Status == "available"; snapshot = snapshots.First(); } Console.WriteLine( $"Snapshot {snapshot.DBClusterSnapshotIdentifier} status is {snapshot.Status}."); Console.WriteLine(sepBar); return snapshot; } /// /// Clean up resources from the scenario. /// /// The instance to clean up. /// The cluster to clean up. /// The parameter group to clean up. ///Async Task. private static async Task CleanupResources( DBInstance? newInstance, DBCluster? newCluster, DBClusterParameterGroup? parameterGroup) { Console.WriteLine(new string('-', 80)); Console.WriteLine($"Clean up resources."); if (newInstance is not null && GetYesNoResponse($"\tClean up instance {newInstance.DBInstanceIdentifier}? (y/n)")) { // Delete the DB instance. Console.WriteLine($"17. Deleting the DB instance {newInstance.DBInstanceIdentifier}."); await auroraWrapper.DeleteDBInstanceByIdentifierAsync(newInstance.DBInstanceIdentifier); } if (newCluster is not null && GetYesNoResponse($"\tClean up cluster {newCluster.DBClusterIdentifier}? (y/n)")) { // Delete the DB cluster. Console.WriteLine($"18. Deleting the DB cluster {newCluster.DBClusterIdentifier}."); await auroraWrapper.DeleteDBClusterByIdentifierAsync(newCluster.DBClusterIdentifier); // Wait for the DB cluster to delete. Console.WriteLine($"19. Waiting for the DB cluster to delete..."); bool isClusterDeleted = false; while (!isClusterDeleted) { Console.Write("."); Thread.Sleep(5000); var cluster = await auroraWrapper.DescribeDBClustersPagedAsync(); isClusterDeleted = cluster.All(i => i.DBClusterIdentifier != newCluster.DBClusterIdentifier); } Console.WriteLine("DB cluster deleted."); } if (parameterGroup is not null && GetYesNoResponse($"\tClean up parameter group? (y/n)")) { Console.WriteLine($"20. Deleting the DB parameter group {parameterGroup.DBClusterParameterGroupName}."); await auroraWrapper.DeleteClusterParameterGroupByNameAsync(parameterGroup.DBClusterParameterGroupName); Console.WriteLine("Parameter group deleted."); } Console.WriteLine(new string('-', 80)); } ////// Get a yes or no response from the user. /// /// The question string to print on the console. ///True if the user responds with a yes. private static bool GetYesNoResponse(string question) { Console.WriteLine(question); var ynResponse = Console.ReadLine(); var response = ynResponse != null && ynResponse.Equals("y", StringComparison.InvariantCultureIgnoreCase); return response; }Wrapper methods that are called by the scenario to manage Aurora actions.
using Amazon.RDS; using Amazon.RDS.Model; namespace AuroraActions; ////// Wrapper for the Amazon Aurora cluster client operations. /// public class AuroraWrapper { private readonly IAmazonRDS _amazonRDS; public AuroraWrapper(IAmazonRDS amazonRDS) { _amazonRDS = amazonRDS; } ////// Get a list of DB engine versions for a particular DB engine. /// /// The name of the engine. /// Optional parameter group family name. ///A list of DBEngineVersions. public async Task- > DescribeDBEngineVersionsForEngineAsync(string engine,
string? parameterGroupFamily = null)
{
var response = await _amazonRDS.DescribeDBEngineVersionsAsync(
new DescribeDBEngineVersionsRequest()
{
Engine = engine,
DBParameterGroupFamily = parameterGroupFamily
});
return response.DBEngineVersions;
}
///
/// Create a custom cluster parameter group. /// /// The family of the parameter group. /// The name for the new parameter group. /// A description for the new parameter group. ///The new parameter group object. public async TaskCreateCustomClusterParameterGroupAsync( string parameterGroupFamily, string groupName, string description) { var request = new CreateDBClusterParameterGroupRequest { DBParameterGroupFamily = parameterGroupFamily, DBClusterParameterGroupName = groupName, Description = description, }; var response = await _amazonRDS.CreateDBClusterParameterGroupAsync(request); return response.DBClusterParameterGroup; } /// /// Describe the cluster parameters in a parameter group. /// /// The name of the parameter group. /// The optional name of the source filter. ///The collection of parameters. public async Task- > DescribeDBClusterParametersInGroupAsync(string groupName, string? source = null)
{
var paramList = new List
(); DescribeDBClusterParametersResponse response; var request = new DescribeDBClusterParametersRequest { DBClusterParameterGroupName = groupName, Source = source, }; // Get the full list if there are multiple pages. do { response = await _amazonRDS.DescribeDBClusterParametersAsync(request); paramList.AddRange(response.Parameters); request.Marker = response.Marker; } while (response.Marker is not null); return paramList; } /// /// Get the description of a DB cluster parameter group by name. /// /// The name of the DB parameter group to describe. ///The parameter group description. public async TaskDescribeCustomDBClusterParameterGroupAsync(string name) { var response = await _amazonRDS.DescribeDBClusterParameterGroupsAsync( new DescribeDBClusterParameterGroupsRequest() { DBClusterParameterGroupName = name }); return response.DBClusterParameterGroups.FirstOrDefault(); } /// /// Modify the specified integer parameters with new values from user input. /// /// The group name for the parameters. /// The list of integer parameters to modify. /// Optional int value to set for parameters. ///The name of the group that was modified. public async TaskModifyIntegerParametersInGroupAsync(string groupName, List parameters, int newValue = 0) { foreach (var p in parameters) { if (p.IsModifiable.GetValueOrDefault() && 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; } /// /// Get a list of orderable DB instance options for a specific /// engine and engine version. /// /// Name of the engine. /// Version of the engine. ///List of OrderableDBInstanceOptions. public async Task- > DescribeOrderableDBInstanceOptionsPagedAsync(string engine, string engineVersion)
{
// Use a paginator to get a list of DB instance options.
var results = new List
(); var paginateInstanceOptions = _amazonRDS.Paginators.DescribeOrderableDBInstanceOptions( new DescribeOrderableDBInstanceOptionsRequest() { Engine = engine, EngineVersion = engineVersion, }); // Get the entire list using the paginator. await foreach (var instanceOptions in paginateInstanceOptions.OrderableDBInstanceOptions) { results.Add(instanceOptions); } return results; } /// /// Delete a particular parameter group by name. /// /// The name of the parameter group. ///True if successful. public async TaskDeleteClusterParameterGroupByNameAsync(string groupName) { var request = new DeleteDBClusterParameterGroupRequest { DBClusterParameterGroupName = groupName, }; var response = await _amazonRDS.DeleteDBClusterParameterGroupAsync(request); return response.HttpStatusCode == System.Net.HttpStatusCode.OK; } /// /// Create a new cluster and database. /// /// The name of the new database. /// The identifier of the cluster. /// The name of the parameter group. /// The engine to use for the new cluster. /// The version of the engine to use. /// The admin username. /// The primary admin password. ///The cluster object. public async TaskCreateDBClusterWithAdminAsync( 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; } /// /// Returns a list of DB instances. /// /// Optional name of a specific DB instance. ///List of DB instances. public async Task- > DescribeDBInstancesPagedAsync(string? dbInstanceIdentifier = null)
{
var results = new List
(); var instancesPaginator = _amazonRDS.Paginators.DescribeDBInstances( new DescribeDBInstancesRequest { DBInstanceIdentifier = dbInstanceIdentifier }); // Get the entire list using the paginator. await foreach (var instances in instancesPaginator.DBInstances) { results.Add(instances); } return results; } /// /// Returns a list of DB clusters. /// /// Optional name of a specific DB cluster. ///List of DB clusters. public async Task- > DescribeDBClustersPagedAsync(string? dbClusterIdentifier = null)
{
var results = new List
(); DescribeDBClustersResponse response; DescribeDBClustersRequest request = new DescribeDBClustersRequest { DBClusterIdentifier = dbClusterIdentifier }; // Get the full list if there are multiple pages. do { response = await _amazonRDS.DescribeDBClustersAsync(request); if (response.DBClusters != null) { results.AddRange(response.DBClusters); } request.Marker = response.Marker; } while (response.Marker is not null); return results; } /// /// Create an Amazon Relational Database Service (Amazon RDS) DB instance /// with a particular set of properties. Use the action DescribeDBInstancesAsync /// to determine when the DB instance is ready to use. /// /// DB instance identifier. /// DB cluster identifier. /// The engine for the DB instance. /// Version for the DB instance. /// Class for the DB instance. ///DB instance object. public async TaskCreateDBInstanceInClusterAsync( string dbClusterIdentifier, string dbInstanceIdentifier, string dbEngine, string dbEngineVersion, string instanceClass) { // When creating the instance within a cluster, do not specify the name or size. var response = await _amazonRDS.CreateDBInstanceAsync( new CreateDBInstanceRequest() { DBClusterIdentifier = dbClusterIdentifier, DBInstanceIdentifier = dbInstanceIdentifier, Engine = dbEngine, EngineVersion = dbEngineVersion, DBInstanceClass = instanceClass }); return response.DBInstance; } /// /// Create a snapshot of a cluster. /// /// DB cluster identifier. /// Identifier for the snapshot. ///DB snapshot object. public async TaskCreateClusterSnapshotByIdentifierAsync(string dbClusterIdentifier, string snapshotIdentifier) { var response = await _amazonRDS.CreateDBClusterSnapshotAsync( new CreateDBClusterSnapshotRequest() { DBClusterIdentifier = dbClusterIdentifier, DBClusterSnapshotIdentifier = snapshotIdentifier, }); return response.DBClusterSnapshot; } /// /// Return a list of DB snapshots for a particular DB cluster. /// /// DB cluster identifier. ///List of DB snapshots. public async Task- > DescribeDBClusterSnapshotsByIdentifierAsync(string dbClusterIdentifier)
{
var results = new List
(); DescribeDBClusterSnapshotsResponse response; DescribeDBClusterSnapshotsRequest request = new DescribeDBClusterSnapshotsRequest { DBClusterIdentifier = dbClusterIdentifier }; // Get the full list if there are multiple pages. do { response = await _amazonRDS.DescribeDBClusterSnapshotsAsync(request); results.AddRange(response.DBClusterSnapshots); request.Marker = response.Marker; } while (response.Marker is not null); return results; } /// /// Delete a particular DB cluster. /// /// DB cluster identifier. ///DB cluster object. public async TaskDeleteDBClusterByIdentifierAsync(string dbClusterIdentifier) { var response = await _amazonRDS.DeleteDBClusterAsync( new DeleteDBClusterRequest() { DBClusterIdentifier = dbClusterIdentifier, SkipFinalSnapshot = true }); return response.DBCluster; } /// /// Delete a particular DB instance. /// /// DB instance identifier. ///DB instance object. public async TaskDeleteDBInstanceByIdentifierAsync(string dbInstanceIdentifier) { var response = await _amazonRDS.DeleteDBInstanceAsync( new DeleteDBInstanceRequest() { DBInstanceIdentifier = dbInstanceIdentifier, SkipFinalSnapshot = true, DeleteAutomatedBackups = true }); return response.DBInstance; } } -
For API details, see the following topics in AWS SDK for .NET API Reference.
-
Actions
The following code example shows how to use CreateDBCluster.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. ////// Create a new cluster and database. /// /// The name of the new database. /// The identifier of the cluster. /// The name of the parameter group. /// The engine to use for the new cluster. /// The version of the engine to use. /// The admin username. /// The primary admin password. ///The cluster object. public async TaskCreateDBClusterWithAdminAsync( 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 AWS SDK for .NET API Reference.
-
The following code example shows how to use CreateDBClusterParameterGroup.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. ////// Create a custom cluster parameter group. /// /// The family of the parameter group. /// The name for the new parameter group. /// A description for the new parameter group. ///The new parameter group object. public async TaskCreateCustomClusterParameterGroupAsync( string parameterGroupFamily, string groupName, string description) { var request = new CreateDBClusterParameterGroupRequest { DBParameterGroupFamily = parameterGroupFamily, DBClusterParameterGroupName = groupName, Description = description, }; var response = await _amazonRDS.CreateDBClusterParameterGroupAsync(request); return response.DBClusterParameterGroup; } -
For API details, see CreateDBClusterParameterGroup in AWS SDK for .NET API Reference.
-
The following code example shows how to use CreateDBClusterSnapshot.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. ////// Create a snapshot of a cluster. /// /// DB cluster identifier. /// Identifier for the snapshot. ///DB snapshot object. public async TaskCreateClusterSnapshotByIdentifierAsync(string dbClusterIdentifier, string snapshotIdentifier) { var response = await _amazonRDS.CreateDBClusterSnapshotAsync( new CreateDBClusterSnapshotRequest() { DBClusterIdentifier = dbClusterIdentifier, DBClusterSnapshotIdentifier = snapshotIdentifier, }); return response.DBClusterSnapshot; } -
For API details, see CreateDBClusterSnapshot in AWS SDK for .NET API Reference.
-
The following code example shows how to use CreateDBInstance.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. ////// Create an Amazon Relational Database Service (Amazon RDS) DB instance /// with a particular set of properties. Use the action DescribeDBInstancesAsync /// to determine when the DB instance is ready to use. /// /// DB instance identifier. /// DB cluster identifier. /// The engine for the DB instance. /// Version for the DB instance. /// Class for the DB instance. ///DB instance object. public async TaskCreateDBInstanceInClusterAsync( string dbClusterIdentifier, string dbInstanceIdentifier, string dbEngine, string dbEngineVersion, string instanceClass) { // When creating the instance within a cluster, do not specify the name or size. var response = await _amazonRDS.CreateDBInstanceAsync( new CreateDBInstanceRequest() { DBClusterIdentifier = dbClusterIdentifier, DBInstanceIdentifier = dbInstanceIdentifier, Engine = dbEngine, EngineVersion = dbEngineVersion, DBInstanceClass = instanceClass }); return response.DBInstance; } -
For API details, see CreateDBInstance in AWS SDK for .NET API Reference.
-
The following code example shows how to use DeleteDBCluster.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. ////// Delete a particular DB cluster. /// /// DB cluster identifier. ///DB cluster object. public async TaskDeleteDBClusterByIdentifierAsync(string dbClusterIdentifier) { var response = await _amazonRDS.DeleteDBClusterAsync( new DeleteDBClusterRequest() { DBClusterIdentifier = dbClusterIdentifier, SkipFinalSnapshot = true }); return response.DBCluster; } -
For API details, see DeleteDBCluster in AWS SDK for .NET API Reference.
-
The following code example shows how to use DeleteDBClusterParameterGroup.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. ////// Delete a particular parameter group by name. /// /// The name of the parameter group. ///True if successful. public async TaskDeleteClusterParameterGroupByNameAsync(string groupName) { var request = new DeleteDBClusterParameterGroupRequest { DBClusterParameterGroupName = groupName, }; var response = await _amazonRDS.DeleteDBClusterParameterGroupAsync(request); return response.HttpStatusCode == System.Net.HttpStatusCode.OK; } -
For API details, see DeleteDBClusterParameterGroup in AWS SDK for .NET API Reference.
-
The following code example shows how to use DeleteDBInstance.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. ////// Delete a particular DB instance. /// /// DB instance identifier. ///DB instance object. public async TaskDeleteDBInstanceByIdentifierAsync(string dbInstanceIdentifier) { var response = await _amazonRDS.DeleteDBInstanceAsync( new DeleteDBInstanceRequest() { DBInstanceIdentifier = dbInstanceIdentifier, SkipFinalSnapshot = true, DeleteAutomatedBackups = true }); return response.DBInstance; } -
For API details, see DeleteDBInstance in AWS SDK for .NET API Reference.
-
The following code example shows how to use DescribeDBClusterParameterGroups.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. ////// Get the description of a DB cluster parameter group by name. /// /// The name of the DB parameter group to describe. ///The parameter group description. public async TaskDescribeCustomDBClusterParameterGroupAsync(string name) { var response = await _amazonRDS.DescribeDBClusterParameterGroupsAsync( new DescribeDBClusterParameterGroupsRequest() { DBClusterParameterGroupName = name }); return response.DBClusterParameterGroups.FirstOrDefault(); } -
For API details, see DescribeDBClusterParameterGroups in AWS SDK for .NET API Reference.
-
The following code example shows how to use DescribeDBClusterParameters.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. ////// Describe the cluster parameters in a parameter group. /// /// The name of the parameter group. /// The optional name of the source filter. ///The collection of parameters. public async Task- > DescribeDBClusterParametersInGroupAsync(string groupName, string? source = null)
{
var paramList = new List
(); DescribeDBClusterParametersResponse response; var request = new DescribeDBClusterParametersRequest { DBClusterParameterGroupName = groupName, Source = source, }; // Get the full list if there are multiple pages. do { response = await _amazonRDS.DescribeDBClusterParametersAsync(request); paramList.AddRange(response.Parameters); request.Marker = response.Marker; } while (response.Marker is not null); return paramList; } -
For API details, see DescribeDBClusterParameters in AWS SDK for .NET API Reference.
-
The following code example shows how to use DescribeDBClusterSnapshots.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. ////// Return a list of DB snapshots for a particular DB cluster. /// /// DB cluster identifier. ///List of DB snapshots. public async Task- > DescribeDBClusterSnapshotsByIdentifierAsync(string dbClusterIdentifier)
{
var results = new List
(); DescribeDBClusterSnapshotsResponse response; DescribeDBClusterSnapshotsRequest request = new DescribeDBClusterSnapshotsRequest { DBClusterIdentifier = dbClusterIdentifier }; // Get the full list if there are multiple pages. do { response = await _amazonRDS.DescribeDBClusterSnapshotsAsync(request); results.AddRange(response.DBClusterSnapshots); request.Marker = response.Marker; } while (response.Marker is not null); return results; } -
For API details, see DescribeDBClusterSnapshots in AWS SDK for .NET API Reference.
-
The following code example shows how to use DescribeDBClusters.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. ////// Returns a list of DB clusters. /// /// Optional name of a specific DB cluster. ///List of DB clusters. public async Task- > DescribeDBClustersPagedAsync(string? dbClusterIdentifier = null)
{
var results = new List
(); DescribeDBClustersResponse response; DescribeDBClustersRequest request = new DescribeDBClustersRequest { DBClusterIdentifier = dbClusterIdentifier }; // Get the full list if there are multiple pages. do { response = await _amazonRDS.DescribeDBClustersAsync(request); if (response.DBClusters != null) { results.AddRange(response.DBClusters); } request.Marker = response.Marker; } while (response.Marker is not null); return results; } -
For API details, see DescribeDBClusters in AWS SDK for .NET API Reference.
-
The following code example shows how to use DescribeDBEngineVersions.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. ////// Get a list of DB engine versions for a particular DB engine. /// /// The name of the engine. /// Optional parameter group family name. ///A list of DBEngineVersions. public async Task- > DescribeDBEngineVersionsForEngineAsync(string engine,
string? parameterGroupFamily = null)
{
var response = await _amazonRDS.DescribeDBEngineVersionsAsync(
new DescribeDBEngineVersionsRequest()
{
Engine = engine,
DBParameterGroupFamily = parameterGroupFamily
});
return response.DBEngineVersions;
}
-
For API details, see DescribeDBEngineVersions in AWS SDK for .NET API Reference.
-
The following code example shows how to use DescribeDBInstances.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. ////// Returns a list of DB instances. /// /// Optional name of a specific DB instance. ///List of DB instances. public async Task- > DescribeDBInstancesPagedAsync(string? dbInstanceIdentifier = null)
{
var results = new List
(); var instancesPaginator = _amazonRDS.Paginators.DescribeDBInstances( new DescribeDBInstancesRequest { DBInstanceIdentifier = dbInstanceIdentifier }); // Get the entire list using the paginator. await foreach (var instances in instancesPaginator.DBInstances) { results.Add(instances); } return results; } -
For API details, see DescribeDBInstances in AWS SDK for .NET API Reference.
-
The following code example shows how to use DescribeOrderableDBInstanceOptions.
- SDK for .NET (v4)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. ////// Get a list of orderable DB instance options for a specific /// engine and engine version. /// /// Name of the engine. /// Version of the engine. ///List of OrderableDBInstanceOptions. public async Task- > DescribeOrderableDBInstanceOptionsPagedAsync(string engine, string engineVersion)
{
// Use a paginator to get a list of DB instance options.
var results = new List
(); var paginateInstanceOptions = _amazonRDS.Paginators.DescribeOrderableDBInstanceOptions( new DescribeOrderableDBInstanceOptionsRequest() { Engine = engine, EngineVersion = engineVersion, }); // Get the entire list using the paginator. await foreach (var instanceOptions in paginateInstanceOptions.OrderableDBInstanceOptions) { results.Add(instanceOptions); } return results; } -
For API details, see DescribeOrderableDBInstanceOptions in AWS SDK for .NET API Reference.
-
The following code example shows how to use ModifyDBClusterParameterGroup.
- SDK for .NET (v4)
-
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 specified integer parameters with new values from user input. /// /// The group name for the parameters. /// The list of integer parameters to modify. /// Optional int value to set for parameters. ///The name of the group that was modified. public async TaskModifyIntegerParametersInGroupAsync(string groupName, List parameters, int newValue = 0) { foreach (var p in parameters) { if (p.IsModifiable.GetValueOrDefault() && 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; } -
For API details, see ModifyDBClusterParameterGroup in AWS SDK for .NET API Reference.
-