사용하는 Amazon RDS 예제 AWS SDK for .NET - AWS SDK for .NET

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

사용하는 Amazon RDS 예제 AWS SDK for .NET

다음 코드 예제는 AWS SDK for .NET with Amazon을 사용하여 작업을 수행하고 일반적인 시나리오를 구현하는 방법을 보여줍니다RDS.

기본 사항은 서비스 내에서 필수 작업을 수행하는 방법을 보여주는 코드 예제입니다.

작업은 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 작업은 개별 서비스 함수를 직접적으로 호출하는 방법을 보여주며 관련 시나리오의 컨텍스트에 맞는 작업을 볼 수 있습니다.

시나리오는 동일한 서비스 내에서 또는 다른 AWS 서비스와 결합된 상태에서 여러 함수를 호출하여 특정 태스크를 수행하는 방법을 보여주는 코드 예제입니다.

각 예제에는 전체 소스 코드에 대한 링크가 포함되어 있으며, 여기에서 상황에 맞게 코드를 설정하고 실행하는 방법에 대한 지침을 찾을 수 있습니다.

시작하기

다음 코드 예제는 Amazon 사용을 시작하는 방법을 보여줍니다RDS.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

using System; using System.Threading.Tasks; using Amazon.RDS; using Amazon.RDS.Model; namespace RDSActions; public static class HelloRds { static async Task Main(string[] args) { var rdsClient = new AmazonRDSClient(); Console.WriteLine($"Hello Amazon RDS! Following are some of your DB instances:"); Console.WriteLine(); // You can use await and any of the async methods to get a response. // Let's get the first twenty DB instances. var response = await rdsClient.DescribeDBInstancesAsync( new DescribeDBInstancesRequest() { MaxRecords = 20 // Must be between 20 and 100. }); foreach (var instance in response.DBInstances) { Console.WriteLine($"\tDB name: {instance.DBName}"); Console.WriteLine($"\tArn: {instance.DBInstanceArn}"); Console.WriteLine($"\tIdentifier: {instance.DBInstanceIdentifier}"); Console.WriteLine(); } } }
  • 자세한 API 내용은 escribeDBInstances AWS SDK for .NET API참조의 D를 참조하십시오.

기본 사항

다음 코드 예시는 다음과 같은 작업을 수행하는 방법을 보여줍니다.

  • 사용자 지정 DB 파라미터 그룹을 생성하고 파라미터 값을 설정합니다.

  • 파라미터 그룹을 사용하도록 구성된 DB 인스턴스를 생성합니다. DB 인스턴스에는 데이터베이스도 포함되어 있습니다.

  • 인스턴스의 스냅샷을 만듭니다.

  • 인스턴스 및 파라미터 그룹을 삭제합니다.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

명령 프롬프트에서 대화형 시나리오를 실행합니다.

/// <summary> /// Scenario for RDS DB instance example. /// </summary> public class RDSInstanceScenario { /* Before running this .NET code example, set up your development environment, including your credentials. This .NET example performs the following tasks: 1. Returns a list of the available DB engine families using the DescribeDBEngineVersionsAsync method. 2. Selects an engine family and creates a custom DB parameter group using the CreateDBParameterGroupAsync method. 3. Gets the parameter groups using the DescribeDBParameterGroupsAsync method. 4. Gets parameters in the group using the DescribeDBParameters method. 5. Parses and displays parameters in the group. 6. Modifies both the auto_increment_offset and auto_increment_increment parameters using the ModifyDBParameterGroupAsync method. 7. Gets and displays the updated parameters using the DescribeDBParameters method with a source of "user". 8. Gets a list of allowed engine versions using the DescribeDBEngineVersionsAsync method. 9. Displays and selects from a list of micro instance classes available for the selected engine and version. 10. Creates an RDS DB instance that contains a MySql database and uses the parameter group using the CreateDBInstanceAsync method. 11. Waits for DB instance to be ready using the DescribeDBInstancesAsync method. 12. Prints out the connection endpoint string for the new DB instance. 13. Creates a snapshot of the DB instance using the CreateDBSnapshotAsync method. 14. Waits for DB snapshot to be ready using the DescribeDBSnapshots method. 15. Deletes the DB instance using the DeleteDBInstanceAsync method. 16. Waits for DB instance to be deleted using the DescribeDbInstances method. 17. Deletes the parameter group using the DeleteDBParameterGroupAsync. */ private static readonly string sepBar = new('-', 80); private static RDSWrapper rdsWrapper = null!; private static ILogger logger = null!; private static readonly string engine = "mysql"; static async Task Main(string[] args) { // Set up dependency injection for the Amazon RDS service. using var host = Host.CreateDefaultBuilder(args) .ConfigureLogging(logging => logging.AddFilter("System", LogLevel.Debug) .AddFilter<DebugLoggerProvider>("Microsoft", LogLevel.Information) .AddFilter<ConsoleLoggerProvider>("Microsoft", LogLevel.Trace)) .ConfigureServices((_, services) => services.AddAWSService<IAmazonRDS>() .AddTransient<RDSWrapper>() ) .Build(); logger = LoggerFactory.Create(builder => { builder.AddConsole(); }).CreateLogger<RDSInstanceScenario>(); rdsWrapper = host.Services.GetRequiredService<RDSWrapper>(); Console.WriteLine(sepBar); Console.WriteLine( "Welcome to the Amazon Relational Database Service (Amazon RDS) DB instance scenario example."); Console.WriteLine(sepBar); try { var parameterGroupFamily = await ChooseParameterGroupFamily(); var parameterGroup = await CreateDbParameterGroup(parameterGroupFamily); var parameters = await DescribeParametersInGroup(parameterGroup.DBParameterGroupName, new List<string> { "auto_increment_offset", "auto_increment_increment" }); await ModifyParameters(parameterGroup.DBParameterGroupName, parameters); await DescribeUserSourceParameters(parameterGroup.DBParameterGroupName); var engineVersionChoice = await ChooseDbEngineVersion(parameterGroupFamily); var instanceChoice = await ChooseDbInstanceClass(engine, engineVersionChoice.EngineVersion); var newInstanceIdentifier = "Example-Instance-" + DateTime.Now.Ticks; var newInstance = await CreateRdsNewInstance(parameterGroup, engine, engineVersionChoice.EngineVersion, instanceChoice.DBInstanceClass, newInstanceIdentifier); if (newInstance != null) { DisplayConnectionString(newInstance); await CreateSnapshot(newInstance); await DeleteRdsInstance(newInstance); } await DeleteParameterGroup(parameterGroup); Console.WriteLine("Scenario complete."); Console.WriteLine(sepBar); } catch (Exception ex) { logger.LogError(ex, "There was a problem executing the scenario."); } } /// <summary> /// Choose the RDS DB parameter group family from a list of available options. /// </summary> /// <returns>The selected parameter group family.</returns> public static async Task<string> ChooseParameterGroupFamily() { Console.WriteLine(sepBar); // 1. Get a list of available engines. var engines = await rdsWrapper.DescribeDBEngineVersions(engine); Console.WriteLine("1. The following is a list of available DB parameter group families:"); int i = 1; var parameterGroupFamilies = engines.GroupBy(e => e.DBParameterGroupFamily).ToList(); foreach (var parameterGroupFamily in parameterGroupFamilies) { // List the available parameter group families. Console.WriteLine( $"\t{i}. Family: {parameterGroupFamily.Key}"); i++; } var choiceNumber = 0; while (choiceNumber < 1 || choiceNumber > parameterGroupFamilies.Count) { Console.WriteLine("Select an available DB parameter group family by entering a number from the list above:"); var choice = Console.ReadLine(); Int32.TryParse(choice, out choiceNumber); } var parameterGroupFamilyChoice = parameterGroupFamilies[choiceNumber - 1]; Console.WriteLine(sepBar); return parameterGroupFamilyChoice.Key; } /// <summary> /// Create and get information on a DB parameter group. /// </summary> /// <param name="dbParameterGroupFamily">The DBParameterGroupFamily for the new DB parameter group.</param> /// <returns>The new DBParameterGroup.</returns> public static async Task<DBParameterGroup> CreateDbParameterGroup(string dbParameterGroupFamily) { Console.WriteLine(sepBar); Console.WriteLine($"2. Create new DB parameter group with family {dbParameterGroupFamily}:"); var parameterGroup = await rdsWrapper.CreateDBParameterGroup( "ExampleParameterGroup-" + DateTime.Now.Ticks, dbParameterGroupFamily, "New example parameter group"); var groupInfo = await rdsWrapper.DescribeDBParameterGroups(parameterGroup .DBParameterGroupName); Console.WriteLine( $"3. New DB parameter group: \n\t{groupInfo[0].Description}, \n\tARN {groupInfo[0].DBParameterGroupArn}"); Console.WriteLine(sepBar); return parameterGroup; } /// <summary> /// Get and describe parameters from a DBParameterGroup. /// </summary> /// <param name="parameterGroupName">Name of the DBParameterGroup.</param> /// <param name="parameterNames">Optional specific names of parameters to describe.</param> /// <returns>The list of requested parameters.</returns> public static async Task<List<Parameter>> DescribeParametersInGroup(string parameterGroupName, List<string>? parameterNames = null) { Console.WriteLine(sepBar); Console.WriteLine("4. Get some parameters from the group."); Console.WriteLine(sepBar); var parameters = await rdsWrapper.DescribeDBParameters(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; } /// <summary> /// Modify a parameter from a DBParameterGroup. /// </summary> /// <param name="parameterGroupName">Name of the DBParameterGroup.</param> /// <param name="parameters">The parameters to modify.</param> /// <returns>Async task.</returns> public static async Task ModifyParameters(string parameterGroupName, List<Parameter> parameters) { Console.WriteLine(sepBar); Console.WriteLine("6. Modify some parameters in the group."); foreach (var p in parameters) { if (p.IsModifiable && p.DataType == "integer") { int newValue = 0; while (newValue == 0) { Console.WriteLine( $"Enter a new value for {p.ParameterName} from the allowed values {p.AllowedValues} "); var choice = Console.ReadLine(); Int32.TryParse(choice, out newValue); } p.ParameterValue = newValue.ToString(); } } await rdsWrapper.ModifyDBParameterGroup(parameterGroupName, parameters); Console.WriteLine(sepBar); } /// <summary> /// Describe the user source parameters in the group. /// </summary> /// <param name="parameterGroupName">Name of the DBParameterGroup.</param> /// <returns>Async task.</returns> public static async Task DescribeUserSourceParameters(string parameterGroupName) { Console.WriteLine(sepBar); Console.WriteLine("7. Describe user source parameters in the group."); var parameters = await rdsWrapper.DescribeDBParameters(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); } /// <summary> /// Choose a DB engine version. /// </summary> /// <param name="dbParameterGroupFamily">DB parameter group family for engine choice.</param> /// <returns>The selected engine version.</returns> public static async Task<DBEngineVersion> ChooseDbEngineVersion(string dbParameterGroupFamily) { Console.WriteLine(sepBar); // Get a list of allowed engines. var allowedEngines = await rdsWrapper.DescribeDBEngineVersions(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}. Engine: {version.Engine} Version {version.EngineVersion}."); 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; } /// <summary> /// Choose a DB instance class for a particular engine and engine version. /// </summary> /// <param name="engine">DB engine for DB instance choice.</param> /// <param name="engineVersion">DB engine version for DB instance choice.</param> /// <returns>The selected orderable DB instance option.</returns> public static async Task<OrderableDBInstanceOption> ChooseDbInstanceClass(string engine, string engineVersion) { Console.WriteLine(sepBar); // Get a list of allowed DB instance classes. var allowedInstances = await rdsWrapper.DescribeOrderableDBInstanceOptions(engine, engineVersion); Console.WriteLine($"8. Available micro DB instance classes for engine {engine} and version {engineVersion}:"); int i = 1; // Filter to micro instances for this example. allowedInstances = allowedInstances .Where(i => i.DBInstanceClass.Contains("micro")).ToList(); 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("9. Select an available DB instance class by entering a number from the list above:"); var choice = Console.ReadLine(); Int32.TryParse(choice, out choiceNumber); } var instanceChoice = allowedInstances[choiceNumber - 1]; Console.WriteLine(sepBar); return instanceChoice; } /// <summary> /// Create a new RDS DB instance. /// </summary> /// <param name="parameterGroup">Parameter group to use for the DB instance.</param> /// <param name="engineName">Engine to use for the DB instance.</param> /// <param name="engineVersion">Engine version to use for the DB instance.</param> /// <param name="instanceClass">Instance class to use for the DB instance.</param> /// <param name="instanceIdentifier">Instance identifier to use for the DB instance.</param> /// <returns>The new DB instance.</returns> public static async Task<DBInstance?> CreateRdsNewInstance(DBParameterGroup parameterGroup, string engineName, string engineVersion, string instanceClass, string instanceIdentifier) { Console.WriteLine(sepBar); Console.WriteLine($"10. Create a new DB instance with identifier {instanceIdentifier}."); bool isInstanceReady = false; DBInstance newInstance; var instances = await rdsWrapper.DescribeDBInstances(); isInstanceReady = instances.FirstOrDefault(i => i.DBInstanceIdentifier == instanceIdentifier)?.DBInstanceStatus == "available"; if (isInstanceReady) { Console.WriteLine("Instance already created."); newInstance = instances.First(i => i.DBInstanceIdentifier == instanceIdentifier); } else { Console.WriteLine("Please enter an admin user name:"); var username = Console.ReadLine(); Console.WriteLine("Please enter an admin password:"); var password = Console.ReadLine(); newInstance = await rdsWrapper.CreateDBInstance( "ExampleInstance", instanceIdentifier, parameterGroup.DBParameterGroupName, engineName, engineVersion, instanceClass, 20, username, password ); // 11. Wait for the DB instance to be ready. Console.WriteLine("11. Waiting for DB instance to be ready..."); while (!isInstanceReady) { instances = await rdsWrapper.DescribeDBInstances(instanceIdentifier); isInstanceReady = instances.FirstOrDefault()?.DBInstanceStatus == "available"; newInstance = instances.First(); Thread.Sleep(30000); } } Console.WriteLine(sepBar); return newInstance; } /// <summary> /// Display a connection string for an RDS DB instance. /// </summary> /// <param name="instance">The DB instance to use to get a connection string.</param> public static void DisplayConnectionString(DBInstance instance) { Console.WriteLine(sepBar); // Display the connection string. Console.WriteLine("12. New DB instance connection string: "); Console.WriteLine( $"\n{engine} -h {instance.Endpoint.Address} -P {instance.Endpoint.Port} " + $"-u {instance.MasterUsername} -p [YOUR PASSWORD]\n"); Console.WriteLine(sepBar); } /// <summary> /// Create a snapshot from an RDS DB instance. /// </summary> /// <param name="instance">DB instance to use when creating a snapshot.</param> /// <returns>The snapshot object.</returns> public static async Task<DBSnapshot> CreateSnapshot(DBInstance instance) { Console.WriteLine(sepBar); // Create a snapshot. Console.WriteLine($"13. Creating snapshot from DB instance {instance.DBInstanceIdentifier}."); var snapshot = await rdsWrapper.CreateDBSnapshot(instance.DBInstanceIdentifier, "ExampleSnapshot-" + DateTime.Now.Ticks); // Wait for the snapshot to be available bool isSnapshotReady = false; Console.WriteLine($"14. Waiting for snapshot to be ready..."); while (!isSnapshotReady) { var snapshots = await rdsWrapper.DescribeDBSnapshots(instance.DBInstanceIdentifier); isSnapshotReady = snapshots.FirstOrDefault()?.Status == "available"; snapshot = snapshots.First(); Thread.Sleep(30000); } Console.WriteLine( $"Snapshot {snapshot.DBSnapshotIdentifier} status is {snapshot.Status}."); Console.WriteLine(sepBar); return snapshot; } /// <summary> /// Delete an RDS DB instance. /// </summary> /// <param name="instance">The DB instance to delete.</param> /// <returns>Async task.</returns> public static async Task DeleteRdsInstance(DBInstance newInstance) { Console.WriteLine(sepBar); // Delete the DB instance. Console.WriteLine($"15. Delete the DB instance {newInstance.DBInstanceIdentifier}."); await rdsWrapper.DeleteDBInstance(newInstance.DBInstanceIdentifier); // Wait for the DB instance to delete. Console.WriteLine($"16. Waiting for the DB instance to delete..."); bool isInstanceDeleted = false; while (!isInstanceDeleted) { var instance = await rdsWrapper.DescribeDBInstances(); isInstanceDeleted = instance.All(i => i.DBInstanceIdentifier != newInstance.DBInstanceIdentifier); Thread.Sleep(30000); } Console.WriteLine("DB instance deleted."); Console.WriteLine(sepBar); } /// <summary> /// Delete a DB parameter group. /// </summary> /// <param name="parameterGroup">The parameter group to delete.</param> /// <returns>Async task.</returns> public static async Task DeleteParameterGroup(DBParameterGroup parameterGroup) { Console.WriteLine(sepBar); // Delete the parameter group. Console.WriteLine($"17. Delete the DB parameter group {parameterGroup.DBParameterGroupName}."); await rdsWrapper.DeleteDBParameterGroup(parameterGroup.DBParameterGroupName); Console.WriteLine(sepBar); }

시나리오에서 DB 인스턴스 작업에 대해 사용하는 래퍼 메서드입니다.

/// <summary> /// Wrapper methods to use Amazon Relational Database Service (Amazon RDS) with DB instance operations. /// </summary> public partial class RDSWrapper { private readonly IAmazonRDS _amazonRDS; public RDSWrapper(IAmazonRDS amazonRDS) { _amazonRDS = amazonRDS; } /// <summary> /// Get a list of DB engine versions for a particular DB engine. /// </summary> /// <param name="engine">Name of the engine.</param> /// <param name="dbParameterGroupFamily">Optional parameter group family name.</param> /// <returns>List of DBEngineVersions.</returns> public async Task<List<DBEngineVersion>> DescribeDBEngineVersions(string engine, string dbParameterGroupFamily = null) { var response = await _amazonRDS.DescribeDBEngineVersionsAsync( new DescribeDBEngineVersionsRequest() { Engine = engine, DBParameterGroupFamily = dbParameterGroupFamily }); return response.DBEngineVersions; } /// <summary> /// Get a list of orderable DB instance options for a specific /// engine and engine version. /// </summary> /// <param name="engine">Name of the engine.</param> /// <param name="engineVersion">Version of the engine.</param> /// <returns>List of OrderableDBInstanceOptions.</returns> public async Task<List<OrderableDBInstanceOption>> DescribeOrderableDBInstanceOptions(string engine, string engineVersion) { // Use a paginator to get a list of DB instance options. var results = new List<OrderableDBInstanceOption>(); 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; } /// <summary> /// Returns a list of DB instances. /// </summary> /// <param name="dbInstanceIdentifier">Optional name of a specific DB instance.</param> /// <returns>List of DB instances.</returns> public async Task<List<DBInstance>> DescribeDBInstances(string dbInstanceIdentifier = null) { var results = new List<DBInstance>(); 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; } /// <summary> /// Create an RDS DB instance with a particular set of properties. Use the action DescribeDBInstancesAsync /// to determine when the DB instance is ready to use. /// </summary> /// <param name="dbName">Name for the DB instance.</param> /// <param name="dbInstanceIdentifier">DB instance identifier.</param> /// <param name="parameterGroupName">DB parameter group to associate with the instance.</param> /// <param name="dbEngine">The engine for the DB instance.</param> /// <param name="dbEngineVersion">Version for the DB instance.</param> /// <param name="instanceClass">Class for the DB instance.</param> /// <param name="allocatedStorage">The amount of storage in gibibytes (GiB) to allocate to the DB instance.</param> /// <param name="adminName">Admin user name.</param> /// <param name="adminPassword">Admin user password.</param> /// <returns>DB instance object.</returns> public async Task<DBInstance> CreateDBInstance(string dbName, string dbInstanceIdentifier, string parameterGroupName, string dbEngine, string dbEngineVersion, string instanceClass, int allocatedStorage, string adminName, string adminPassword) { var response = await _amazonRDS.CreateDBInstanceAsync( new CreateDBInstanceRequest() { DBName = dbName, DBInstanceIdentifier = dbInstanceIdentifier, DBParameterGroupName = parameterGroupName, Engine = dbEngine, EngineVersion = dbEngineVersion, DBInstanceClass = instanceClass, AllocatedStorage = allocatedStorage, MasterUsername = adminName, MasterUserPassword = adminPassword }); return response.DBInstance; } /// <summary> /// Delete a particular DB instance. /// </summary> /// <param name="dbInstanceIdentifier">DB instance identifier.</param> /// <returns>DB instance object.</returns> public async Task<DBInstance> DeleteDBInstance(string dbInstanceIdentifier) { var response = await _amazonRDS.DeleteDBInstanceAsync( new DeleteDBInstanceRequest() { DBInstanceIdentifier = dbInstanceIdentifier, SkipFinalSnapshot = true, DeleteAutomatedBackups = true }); return response.DBInstance; }

DB 파라미터 그룹에 대해 시나리오에서 사용하는 래퍼 메서드.

/// <summary> /// Wrapper methods to use Amazon Relational Database Service (Amazon RDS) with parameter groups. /// </summary> public partial class RDSWrapper { /// <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; } /// <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; } /// <summary> /// Update a 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="parameters">List of parameters. Maximum of 20 per request.</param> /// <returns>The updated DB parameter group name.</returns> public async Task<string> ModifyDBParameterGroup( string name, List<Parameter> parameters) { var response = await _amazonRDS.ModifyDBParameterGroupAsync( new ModifyDBParameterGroupRequest() { DBParameterGroupName = name, Parameters = parameters, }); return response.DBParameterGroupName; } /// <summary> /// Delete a DB parameter group. The group cannot be a default DB parameter group /// or be associated with any DB instances. /// </summary> /// <param name="name">Name of the DB parameter group.</param> /// <returns>True if successful.</returns> public async Task<bool> DeleteDBParameterGroup(string name) { var response = await _amazonRDS.DeleteDBParameterGroupAsync( new DeleteDBParameterGroupRequest() { DBParameterGroupName = name, }); return response.HttpStatusCode == HttpStatusCode.OK; } /// <summary> /// Get a list of DB parameters from a specific parameter group. /// </summary> /// <param name="dbParameterGroupName">Name of a specific DB parameter group.</param> /// <param name="source">Optional source for selecting parameters.</param> /// <returns>List of parameter values.</returns> public async Task<List<Parameter>> DescribeDBParameters(string dbParameterGroupName, string source = null) { var results = new List<Parameter>(); var paginateParameters = _amazonRDS.Paginators.DescribeDBParameters( new DescribeDBParametersRequest() { DBParameterGroupName = dbParameterGroupName, Source = source }); // Get the entire list using the paginator. await foreach (var parameters in paginateParameters.Parameters) { results.Add(parameters); } return results; }

시나리오에서 DB 스냅샷 작업에 대해 사용하는 래퍼 메서드입니다.

/// <summary> /// Wrapper methods to use Amazon Relational Database Service (Amazon RDS) with snapshots. /// </summary> public partial class RDSWrapper { /// <summary> /// Create a snapshot of a DB instance. /// </summary> /// <param name="dbInstanceIdentifier">DB instance identifier.</param> /// <param name="snapshotIdentifier">Identifier for the snapshot.</param> /// <returns>DB snapshot object.</returns> public async Task<DBSnapshot> CreateDBSnapshot(string dbInstanceIdentifier, string snapshotIdentifier) { var response = await _amazonRDS.CreateDBSnapshotAsync( new CreateDBSnapshotRequest() { DBSnapshotIdentifier = snapshotIdentifier, DBInstanceIdentifier = dbInstanceIdentifier }); return response.DBSnapshot; } /// <summary> /// Return a list of DB snapshots for a particular DB instance. /// </summary> /// <param name="dbInstanceIdentifier">DB instance identifier.</param> /// <returns>List of DB snapshots.</returns> public async Task<List<DBSnapshot>> DescribeDBSnapshots(string dbInstanceIdentifier) { var results = new List<DBSnapshot>(); var snapshotsPaginator = _amazonRDS.Paginators.DescribeDBSnapshots( new DescribeDBSnapshotsRequest() { DBInstanceIdentifier = dbInstanceIdentifier }); // Get the entire list using the paginator. await foreach (var snapshots in snapshotsPaginator.DBSnapshots) { results.Add(snapshots); } return results; }

작업

다음 코드 예시에서는 CreateDBInstance을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

더 많은 정보가 있어요 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// Create an RDS DB instance with a particular set of properties. Use the action DescribeDBInstancesAsync /// to determine when the DB instance is ready to use. /// </summary> /// <param name="dbName">Name for the DB instance.</param> /// <param name="dbInstanceIdentifier">DB instance identifier.</param> /// <param name="parameterGroupName">DB parameter group to associate with the instance.</param> /// <param name="dbEngine">The engine for the DB instance.</param> /// <param name="dbEngineVersion">Version for the DB instance.</param> /// <param name="instanceClass">Class for the DB instance.</param> /// <param name="allocatedStorage">The amount of storage in gibibytes (GiB) to allocate to the DB instance.</param> /// <param name="adminName">Admin user name.</param> /// <param name="adminPassword">Admin user password.</param> /// <returns>DB instance object.</returns> public async Task<DBInstance> CreateDBInstance(string dbName, string dbInstanceIdentifier, string parameterGroupName, string dbEngine, string dbEngineVersion, string instanceClass, int allocatedStorage, string adminName, string adminPassword) { var response = await _amazonRDS.CreateDBInstanceAsync( new CreateDBInstanceRequest() { DBName = dbName, DBInstanceIdentifier = dbInstanceIdentifier, DBParameterGroupName = parameterGroupName, Engine = dbEngine, EngineVersion = dbEngineVersion, DBInstanceClass = instanceClass, AllocatedStorage = allocatedStorage, MasterUsername = adminName, MasterUserPassword = adminPassword }); return response.DBInstance; }
  • 자세한 API 내용은 reateDBInstance AWS SDK for .NET API참조의 C를 참조하십시오.

다음 코드 예시에서는 CreateDBParameterGroup을 사용하는 방법을 보여 줍니다.

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; }

다음 코드 예시에서는 CreateDBSnapshot을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

자세한 내용은 다음과 같습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// Create a snapshot of a DB instance. /// </summary> /// <param name="dbInstanceIdentifier">DB instance identifier.</param> /// <param name="snapshotIdentifier">Identifier for the snapshot.</param> /// <returns>DB snapshot object.</returns> public async Task<DBSnapshot> CreateDBSnapshot(string dbInstanceIdentifier, string snapshotIdentifier) { var response = await _amazonRDS.CreateDBSnapshotAsync( new CreateDBSnapshotRequest() { DBSnapshotIdentifier = snapshotIdentifier, DBInstanceIdentifier = dbInstanceIdentifier }); return response.DBSnapshot; }
  • 자세한 API 내용은 reateDBSnapshot AWS SDK for .NET API참조의 C를 참조하십시오.

다음 코드 예시에서는 DeleteDBInstance을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

자세한 내용은 다음과 같습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// Delete a particular DB instance. /// </summary> /// <param name="dbInstanceIdentifier">DB instance identifier.</param> /// <returns>DB instance object.</returns> public async Task<DBInstance> DeleteDBInstance(string dbInstanceIdentifier) { var response = await _amazonRDS.DeleteDBInstanceAsync( new DeleteDBInstanceRequest() { DBInstanceIdentifier = dbInstanceIdentifier, SkipFinalSnapshot = true, DeleteAutomatedBackups = true }); return response.DBInstance; }
  • 자세한 API 내용은 eleteDBInstance AWS SDK for .NET API참조의 D를 참조하십시오.

다음 코드 예시에서는 DeleteDBParameterGroup을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// Delete a DB parameter group. The group cannot be a default DB parameter group /// or be associated with any DB instances. /// </summary> /// <param name="name">Name of the DB parameter group.</param> /// <returns>True if successful.</returns> public async Task<bool> DeleteDBParameterGroup(string name) { var response = await _amazonRDS.DeleteDBParameterGroupAsync( new DeleteDBParameterGroupRequest() { DBParameterGroupName = name, }); return response.HttpStatusCode == HttpStatusCode.OK; }

다음 코드 예시에서는 DescribeDBEngineVersions을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

자세한 내용은 다음과 같습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// Get a list of DB engine versions for a particular DB engine. /// </summary> /// <param name="engine">Name of the engine.</param> /// <param name="dbParameterGroupFamily">Optional parameter group family name.</param> /// <returns>List of DBEngineVersions.</returns> public async Task<List<DBEngineVersion>> DescribeDBEngineVersions(string engine, string dbParameterGroupFamily = null) { var response = await _amazonRDS.DescribeDBEngineVersionsAsync( new DescribeDBEngineVersionsRequest() { Engine = engine, DBParameterGroupFamily = dbParameterGroupFamily }); return response.DBEngineVersions; }

다음 코드 예시에서는 DescribeDBInstances을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

자세한 내용은 다음과 같습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// Returns a list of DB instances. /// </summary> /// <param name="dbInstanceIdentifier">Optional name of a specific DB instance.</param> /// <returns>List of DB instances.</returns> public async Task<List<DBInstance>> DescribeDBInstances(string dbInstanceIdentifier = null) { var results = new List<DBInstance>(); 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; }
  • 자세한 API 내용은 escribeDBInstances AWS SDK for .NET API참조의 D를 참조하십시오.

다음 코드 예시에서는 DescribeDBParameterGroups을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <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; }

다음 코드 예시에서는 DescribeDBParameters을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

자세한 내용은 다음과 같습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// Get a list of DB parameters from a specific parameter group. /// </summary> /// <param name="dbParameterGroupName">Name of a specific DB parameter group.</param> /// <param name="source">Optional source for selecting parameters.</param> /// <returns>List of parameter values.</returns> public async Task<List<Parameter>> DescribeDBParameters(string dbParameterGroupName, string source = null) { var results = new List<Parameter>(); var paginateParameters = _amazonRDS.Paginators.DescribeDBParameters( new DescribeDBParametersRequest() { DBParameterGroupName = dbParameterGroupName, Source = source }); // Get the entire list using the paginator. await foreach (var parameters in paginateParameters.Parameters) { results.Add(parameters); } return results; }
  • 자세한 API 내용은 escribeDBParameters AWS SDK for .NET API참조의 D를 참조하십시오.

다음 코드 예시에서는 DescribeDBSnapshots을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// Return a list of DB snapshots for a particular DB instance. /// </summary> /// <param name="dbInstanceIdentifier">DB instance identifier.</param> /// <returns>List of DB snapshots.</returns> public async Task<List<DBSnapshot>> DescribeDBSnapshots(string dbInstanceIdentifier) { var results = new List<DBSnapshot>(); var snapshotsPaginator = _amazonRDS.Paginators.DescribeDBSnapshots( new DescribeDBSnapshotsRequest() { DBInstanceIdentifier = dbInstanceIdentifier }); // Get the entire list using the paginator. await foreach (var snapshots in snapshotsPaginator.DBSnapshots) { results.Add(snapshots); } return results; }
  • 자세한 API 내용은 escribeDBSnapshots AWS SDK for .NET API참조의 D를 참조하십시오.

다음 코드 예시에서는 DescribeOrderableDBInstanceOptions을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// Get a list of orderable DB instance options for a specific /// engine and engine version. /// </summary> /// <param name="engine">Name of the engine.</param> /// <param name="engineVersion">Version of the engine.</param> /// <returns>List of OrderableDBInstanceOptions.</returns> public async Task<List<OrderableDBInstanceOption>> DescribeOrderableDBInstanceOptions(string engine, string engineVersion) { // Use a paginator to get a list of DB instance options. var results = new List<OrderableDBInstanceOption>(); 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; }

다음 코드 예시에서는 ModifyDBParameterGroup을 사용하는 방법을 보여 줍니다.

AWS SDK for .NET
참고

더 많은 정보가 있습니다 GitHub. AWS 코드 예시 리포지토리에서 전체 예시를 찾고 설정 및 실행하는 방법을 배워보세요.

/// <summary> /// Update a 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="parameters">List of parameters. Maximum of 20 per request.</param> /// <returns>The updated DB parameter group name.</returns> public async Task<string> ModifyDBParameterGroup( string name, List<Parameter> parameters) { var response = await _amazonRDS.ModifyDBParameterGroupAsync( new ModifyDBParameterGroupRequest() { DBParameterGroupName = name, Parameters = parameters, }); return response.DBParameterGroupName; }

시나리오

다음 코드 예제는 Amazon Aurora 서버리스 데이터베이스에서 작업 항목을 추적하고 Amazon Simple Email Service (AmazonSES) 를 사용하여 보고서를 보내는 웹 애플리케이션을 생성하는 방법을 보여줍니다.

AWS SDK for .NET

를 사용하여 Amazon Aurora 데이터베이스의 작업 항목을 추적하고 Amazon Simple Email Service (Amazon) 를 사용하여 보고서를 이메일로 보내는 웹 애플리케이션을 생성하는 방법을 보여 줍니다. AWS SDK for .NET SES 이 예제에서는 React.js 로 구축된 프런트 엔드를 사용하여 RESTful a와 상호 작용합니다. NET백엔드.

  • React 웹 애플리케이션을 AWS 서비스와 통합합니다.

  • Aurora 테이블의 항목을 나열, 추가, 업데이트 및 삭제합니다.

  • Amazon을 사용하여 필터링된 작업 항목에 대한 이메일 보고서를 SES 전송합니다.

  • 포함된 AWS CloudFormation 스크립트를 사용하여 예제 리소스를 배포하고 관리합니다.

전체 소스 코드와 설정 및 실행 방법에 대한 지침은 의 전체 예제를 참조하십시오 GitHub.

이 예시에서 사용되는 서비스
  • Aurora

  • 아마존 RDS

  • 아마존 RDS 데이터 서비스

  • 아마존 SES