Implementation for accessing RDS Amazon Relational Database Service

Amazon Relational Database Service (Amazon RDS) is a web service that makes it easier to set up, operate, and scale a relational database in the cloud. It provides cost-efficient, resizeable capacity for an industry-standard relational database and manages common database administration tasks, freeing up developers to focus on what makes their applications and businesses unique.

Amazon RDS gives you access to the capabilities of a MySQL, MariaDB, PostgreSQL, Microsoft SQL Server, Oracle, or Amazon Aurora database server. These capabilities mean that the code, applications, and tools you already use today with your existing databases work with Amazon RDS without modification. Amazon RDS automatically backs up your database and maintains the database software that powers your DB instance. Amazon RDS is flexible: you can scale your database instance's compute resources and storage capacity to meet your application's demand. As with all Amazon Web Services, there are no up-front investments, and you pay only for the resources you use.

This interface reference for Amazon RDS contains documentation for a programming or command line interface you can use to manage Amazon RDS. Note that Amazon RDS is asynchronous, which means that some interfaces might require techniques such as polling or callback functions to determine when a command has been applied. In this reference, the parameter descriptions indicate whether a command is applied immediately, on the next instance reboot, or during the maintenance window. The reference structure is as follows, and we list following some related topics from the user guide.

Amazon RDS API Reference

Amazon RDS User Guide

상속: AmazonServiceClient, IAmazonRDS
예제 #1
2
파일: Program.cs 프로젝트: PMInova/RDSDump
        static void Main(string[] args)
        {
            Console.WriteLine("Started Dump...");

            string databaseNameOrigin = System.Environment.GetEnvironmentVariable("DatabaseNameOrigin", EnvironmentVariableTarget.Machine);
            string databaseNameTarget = System.Environment.GetEnvironmentVariable("DatabaseNameTarget", EnvironmentVariableTarget.Machine);
            string database = System.Environment.GetEnvironmentVariable("Database", EnvironmentVariableTarget.Machine);
            string databaseUser = System.Environment.GetEnvironmentVariable("DatabaseUser", EnvironmentVariableTarget.Machine);
            string databasePassword = System.Environment.GetEnvironmentVariable("DatabasePassword", EnvironmentVariableTarget.Machine);
            string s3BucketName = System.Environment.GetEnvironmentVariable("S3BucketName", EnvironmentVariableTarget.Machine);

            try
            {
                using (AmazonRDSClient rdsClient = new AmazonRDSClient(RegionEndpoint.USWest2))
                {

                    DBSnapshot newerSnapshot = getNewerSnapshot(databaseNameOrigin, rdsClient);
                    Console.WriteLine("Snapshot found: " + newerSnapshot.DBSnapshotIdentifier);

                    restoreSnapshotIntoDBTarget(databaseNameTarget, rdsClient, newerSnapshot);
                    Console.WriteLine("Restoring Snapshot Into RDS account... ");
                    Thread.Sleep(60000);

                    string address = waitUntilDBTargetIsAvailable(databaseNameTarget, rdsClient);

                    Console.WriteLine("Snapshot Restored. Exporting BACPAC to file... ");
                    exportBacpac(database, databaseUser, databasePassword, address);

                    Console.WriteLine("BACPAC exported. Deleting RDS backup database... ");
                    deleteDatabaseByName(databaseNameTarget, rdsClient);

                }

                using (var s3Client = new AmazonS3Client(RegionEndpoint.SAEast1))
                {
                    Console.WriteLine("Uploading BACPAC to S3... ");
                    uploadFileToS3(s3BucketName, "dump.bacpac", s3Client);
                    Console.WriteLine("BACPAC Upload and temporaries deleted!");

                }

                Console.WriteLine("Dump completed successfully!");

            }
            catch (DacServicesException e)
            {
                Console.WriteLine("Error Encountered:{0} Inner Exception: {1}", e.Messages, e.InnerException);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error Encountered:{0} Inner Exception: {1}", e.Message, e.InnerException);
            }
        }
예제 #2
0
        public static AmazonRDSClient GetRdsConnection()
        {
            if (rds == null)
            {
                rds = new AmazonRDSClient(AwsKeyProviders.Key, AwsKeyProviders.Secret, RegionEndpoint.EUWest1);
            }

            return rds;
        }
예제 #3
0
파일: Program.cs 프로젝트: PMInova/RDSDump
        private static void deleteDatabaseByName(string databaseNameTarget, AmazonRDSClient rdsClient)
        {
            DeleteDBInstanceRequest deleteRequest = new DeleteDBInstanceRequest()
            {
                DBInstanceIdentifier = databaseNameTarget,
                SkipFinalSnapshot = true
            };
            DeleteDBInstanceResponse deleteResponse =
                rdsClient.DeleteDBInstance(deleteRequest);

            HttpStatusCode statusCode = deleteResponse.HttpStatusCode;

            if (!statusCode.Equals(HttpStatusCode.OK))
            {
                throw new Exception();
            }
        }
예제 #4
0
파일: Program.cs 프로젝트: PMInova/RDSDump
        private static DBSnapshot getNewerSnapshot(string databaseNameOrigin, AmazonRDSClient rdsClient)
        {
            DescribeDBSnapshotsRequest describeSnapshotsRequest =
            new DescribeDBSnapshotsRequest()
            {
                DBInstanceIdentifier = databaseNameOrigin,
                SnapshotType = "automated"

            };
            DescribeDBSnapshotsResponse describeSnapshotsResponse =
                rdsClient.DescribeDBSnapshots(describeSnapshotsRequest);

            List<DBSnapshot> snapshots = describeSnapshotsResponse.DBSnapshots;

            IEnumerable<DBSnapshot> orderedSnapshots = snapshots.OrderByDescending(x => x.SnapshotCreateTime);

            DBSnapshot newerSnapshot = orderedSnapshots.First();
            return newerSnapshot;
        }
        private OperationResult EstablishClient(AddonManifest manifest, DeveloperOptions devOptions, out AmazonRDSClient client)
        {
            OperationResult result;

            bool requireCreds;
            var manifestProps = manifest.GetProperties().ToDictionary(x => x.Key, x => x.Value);
            var accessKey = manifestProps["AWSClientKey"];
            var secretAccessKey = manifestProps["AWSSecretKey"];
            var regionEndpoint = manifestProps["AWSRegionEndpoint"];

            var prop =
                manifest.Properties.First(
                    p => p.Key.Equals("requireDevCredentials", StringComparison.InvariantCultureIgnoreCase));

            if (bool.TryParse(prop.Value, out requireCreds) && requireCreds)
            {
                if (!ValidateDevCreds(devOptions))
                {
                    client = null;
                    result = new OperationResult()
                    {
                        IsSuccess = false,
                        EndUserMessage =
                            "The add on requires that developer credentials are specified but none were provided."
                    };
                    return result;
                }

                accessKey = devOptions.AccessKey;
                secretAccessKey = devOptions.SecretAccessKey;
            }
            AmazonRDSConfig config = new AmazonRDSConfig() { RegionEndpoint = RegionEndpoint.USEast1 };
            client = new AmazonRDSClient(accessKey, secretAccessKey, config);
            result = new OperationResult { IsSuccess = true };
            return result;
        }
예제 #6
0
 protected virtual AmazonRDS GetClient()
 {
     AmazonCredentials.KeyPair credentials = base.GetCredentials();
     AmazonRDS client = new AmazonRDSClient(credentials.AwsAccessKeyId, credentials.AwsSecretAccessKey);
     return client;
 }
예제 #7
0
파일: Program.cs 프로젝트: PMInova/RDSDump
        private static string waitUntilDBTargetIsAvailable(string databaseNameTarget, AmazonRDSClient rdsClient)
        {
            string status = "";
            string address = "";
            do
            {
                DescribeDBInstancesRequest describeInstancesRequest =
                    new DescribeDBInstancesRequest()
                    {
                        DBInstanceIdentifier = databaseNameTarget
                    };
                DescribeDBInstancesResponse describeInstancesResponse =
                    rdsClient.DescribeDBInstances(describeInstancesRequest);

                DBInstance dbInstance = describeInstancesResponse.DBInstances.First();

                status = dbInstance.DBInstanceStatus;

                if (dbInstance.Endpoint != null)
                {
                    address = dbInstance.Endpoint.Address;
                }
                Thread.Sleep(60000);
            }
            while (status != "available");
            return address;
        }
예제 #8
0
파일: Program.cs 프로젝트: PMInova/RDSDump
        private static void restoreSnapshotIntoDBTarget(string databaseNameTarget, AmazonRDSClient rdsClient, DBSnapshot newerSnapshot)
        {
            RestoreDBInstanceFromDBSnapshotRequest restoreRequest = new RestoreDBInstanceFromDBSnapshotRequest()
            {
                DBSnapshotIdentifier = newerSnapshot.DBSnapshotIdentifier,
                DBInstanceIdentifier = databaseNameTarget

            };

            rdsClient.RestoreDBInstanceFromDBSnapshot(restoreRequest);
        }