AWS Elastic Beanstalk
Developer Guide (API Version 2010-12-01)
AWS services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon AWS.

Adding a Database to Your Elastic Beanstalk Environment

Elastic Beanstalk provides integration with Amazon Relational Database Service (Amazon RDS) to help you add a database instance to your Elastic Beanstalk environment. You can use Elastic Beanstalk to add a MySQL, PostgreSQL, Oracle, or SQL Server database to your environment during or after environment creation. When you add a database instance to your environment, Elastic Beanstalk provides connection information to your application by setting environment properties for the database hostname, port, user name, password, and database name.

A database instance that is part of your environment is tied to the lifecycle of your environment. You can't remove it from your environment once added. If you terminate the environment, the database instance is terminated as well. You can configure Elastic Beanstalk to save a snapshot of the database when you terminate your environment, and restore a database from a snapshot when you add a DB instance to an environment. You might incur charges for storing database snapshots. For more information, see the Backup Storage section of Amazon RDS Pricing.

For a production environment, you can launch a database instance outside of your environment and configure your application to connect to it outside of the functionality provided by Elastic Beanstalk. Using a database instance that is external to your environment requires additional security group and connection string configuration. However, it also lets you connect to the database from multiple environments, use database types not supported with integrated databases, perform blue/green deployments, and tear down your environment without affecting the database instance.

Adding an Amazon RDS DB Instance to Your Environment

You can add a DB instance to your environment by using the Elastic Beanstalk console.

To add a DB instance to your environment

  1. Open the Elastic Beanstalk console.

  2. Navigate to the management page for your environment.

  3. Choose Configuration.

  4. On the Database configuration card, choose Modify.

  5. Choose a DB engine, and enter a user name and password.

  6. Choose Save, and then choose Apply.

You can configure the following options:

  • Snapshot – Choose an existing database snapshot. Elastic Beanstalk restores the snapshot and adds it to your environment. The default value is None, which lets you configure a new database using the other settings on this page.

  • Engine – Choose a database engine.

  • Engine version – Choose a specific version of the database engine.

  • Instance class – Choose the DB instance class. For information about the DB instance classes, see http://amazonaws.cn/rds/.

  • Storage – Choose the amount of storage to provision for your database. You can increase allocated storage later, but you cannot decrease it. For information about storage allocation, see Features.

  • Username – Type a user name using alphanumeric characters.

  • Password – Type a password containing 8–16 printable ASCII characters (excluding /, \, and @).

  • Retention – Choose Create snapshot to create a snapshot of the database when you terminate your environment.

  • Availability – Choose High (Multi-AZ) to run a warm backup in a second Availability Zone for high availability.


        Elastic Beanstalk Auto Scaling Configuration Window

Adding a DB instance takes about 10 minutes. When the environment update is complete, the DB instance's hostname and other connection information are available to your application through the following environment properties:

  • RDS_HOSTNAME – The hostname of the DB instance.

    Amazon RDS console label – Endpoint (this is the hostname)

  • RDS_PORT – The port on which the DB instance accepts connections. The default value varies among DB engines.

    Amazon RDS console label – Port

  • RDS_DB_NAME – The database name, ebdb.

    Amazon RDS console label – DB Name

  • RDS_USERNAME – The user name that you configured for your database.

    Amazon RDS console label – Username

  • RDS_PASSWORD – The password that you configured for your database.

Connecting to the database

Use the connectivity information to connect to your DB from inside your application through environment variables. For more information about using Amazon RDS with your applications, see the following topics.

Configuring an Integrated RDS DB Instance

You can view and modify configuration settings for your DB instance in the Data Tier section on the environment's Configuration page in the environment management console.

To configure your environment's DB instance in the Elastic Beanstalk console

  1. Open the Elastic Beanstalk console.

  2. Navigate to the management page for your environment.

  3. Choose Configuration.

  4. On the Database configuration card, choose Modify.

You can modify the Instance class, Storage, Password, Retention, and Availability settings after database creation. If you change the instance class, Elastic Beanstalk reprovisions the DB instance.

Do not modify settings on the DB instance outside of the functionality provided by Elastic Beanstalk (for example, in the Amazon RDS console).