AWS Elastic Beanstalk
Developer Guide (API Version 2010-12-01)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Using Amazon RDS

With Amazon Relational Database Service (Amazon RDS), you can quickly and easily provision and maintain a MySQL, Oracle, or Microsoft SQL Server instance in the cloud. For more information about Amazon RDS, go to http://aws.amazon.com/rds/.

This topic explains how you can use Amazon RDS with your AWS Elastic Beanstalk .NET application using the AWS Management Console. You can also use the AWS Toolkit for Visual Studio to create your Amazon RDS DB instance. For an example walkthrough using SQL Server, see Get Started.

Note

The instructions in this topic are for non-legacy container types. If you have deployed an AWS Elastic Beanstalk application using a legacy container type, we recommend that you migrate to a non-legacy container type to gain access to new features. For instructions on how to check the container type and migrate your application, see Migrating Your Application from a Legacy Container Type.

To use Amazon RDS from your AWS Elastic Beanstalk application, you need to do the following:

  1. Create an Amazon RDS DB Instance.

  2. Download and install a database driver.

  3. Establish a database connection in your code by using the connectivity information for your Amazon RDS DB Instance.

  4. Deploy your application to AWS Elastic Beanstalk.

This topic walks you through the following:

  • Using a new Amazon RDS DB Instance with your application

  • Using an existing Amazon RDS DB Instance with your application

Using a New Amazon RDS DB Instance with .NET

This topic walks you through creating a new Amazon RDS DB Instance using the console, and then using the RDS connection information with your .NET application.

To create an Amazon RDS DB Instance with .NET

  1. Create an Amazon RDS DB Instance. You can create an RDS DB Instance in one of the following ways:

    • Create an RDS DB Instance when you create a new application version. For instructions using the AWS Elastic Beanstalk console, see Creating New Applications.

    • Create an RDS DB Instance when you launch a new environment with an existing application version. For instructions using the AWS Elastic Beanstalk console, see Launching New Environments.

    • If you already deployed an application to AWS Elastic Beanstalk, you can create an RDS DB Instance and attach it to an existing environment. For instructions using the AWS Elastic Beanstalk console, see Step 4: Deploy New Version.

  2. Download and install a database driver for your development environment.

  3. Establish a database connection in your code using your Amazon RDS DB Instance's connectivity information. You can access your connectivity information using application settings. The following shows how you would connect to the database on an RDS instance.

    NameValueCollection appConfig = ConfigurationManager.AppSettings;
    
    string dbname = appConfig["RDS_DB_NAME"];
    string username = appConfig["RDS_USERNAME"];
    string password = appConfig["RDS_PASSWORD"];
    string hostname = appConfig["RDS_HOSTNAME"];
    string port = appConfig["RDS_PORT"];

    Build your connection string:

    string cs = "server=" + hostname + ";user=" + username + ";database=" + dbname + ";port=" + port + ";password=" + password + ";";

    The following connection string is an example using MySQL.

    "server=mydbinstance.abcdefghijkl.us-east-1.rds.amazonaws.com;user=sa;database=mydb;port=3306;password=******;";
  4. Deploy your updated application to your existing AWS Elastic Beanstalk environment. For information on how to deploy a new application version to an existing environment using the Elastic Beanstalk Console, see Step 4: Deploy New Version. For information on how to deploy your application using Visual Studio, see Develop, Test, and Deploy.

Using an Existing Amazon RDS DB Instance with .NET

Amazon Relational Database Service (Amazon RDS) lets you quickly and easily provision and maintain a MySQL Server instance in the cloud. This topic discusses how you can use Amazon RDS and the MySQL .NET Connector with your AWS Elastic Beanstalk application.

To use an existing Amazon RDS DB Instance and .NET from your AWS Elastic Beanstalk application

  1. Create an AWS Elastic Beanstalk environment in one of the following ways:

    • Create a new application with a new environment. For instructions using the Elastic Beanstalk console, see Creating New Applications. For instructions using Visual Studio, see Develop, Test, and Deploy. You do not need to create an RDS DB Instance with this environment because you already have an existing RDS DB Instance.

    • Launch a new environment with an existing application version. For instructions using the Elastic Beanstalk console, see Launching New Environments. You do not need to create an RDS DB Instance with this environment because you already have an existing RDS DB Instance.

  2. Configure your Amazon RDS DB Security Group to allow access from the Amazon EC2 security group used by your AWS Elastic Beanstalk application. For instructions on how to find the name of your EC2 security group using the AWS Management Console, see Amazon EC2 Security Groups. For more information, go to the "Authorizing Network Access to an Amazon EC2 Security Group" section of Working with DB Security Groups in the Amazon Relational Database Service User Guide.

  3. Download and install a database driver for your development environment.

  4. Create a connection string using your Amazon RDS DB Instance's public DNS name, port number, and (optionally) database name and login credentials. The following example shows a connection string that would connect to a database, mydb, on an RDS instance at mydbinstance.abcdefghijkl.us-east-1.rds.amazonaws.com using port 3306, with the user name "sa" and the password "mypassword".

    string cs = "server=mydbinstance.abcdefghijkl.us-east-1.rds.amazonaws.com;user=sa;database=mydb;port=3306;password=******;";
  5. Deploy your updated application to your existing AWS Elastic Beanstalk environment. For information on how to deploy a new application version to an existing environment using the Elastic Beanstalk Console, see Step 4: Deploy New Version. For information on how to deploy your application using Visual Studio, see Develop, Test, and Deploy.