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.

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.

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.

Note

Elastic Beanstalk creates a master user for the database using the user name and password
you provide. To learn more about the master user and its privileges, see
Master User Account Privileges.

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.

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

Warning

Don't modify settings on the DB instance outside of the functionality provided by
Elastic Beanstalk (for example, in the Amazon RDS console). If you do, your Amazon
RDS
DB configuration might be out of sync with your environment's definition. When you
update or restart your environment, the settings specified in the
environment override any settings you made outside of Elastic Beanstalk.

Configuring an Integrated RDS DB Instance Using Configuration Files

You can configure your environment's DB instance using configuration files. Use the options in the aws:rds:dbinstance namespace. The following example modifies the allocated database
storage size to 100 GB.

Example .ebextensions/db-instance-options.config

option_settings:
aws:rds:dbinstance:
DBAllocatedStorage: 100

If you need to configure DB instance properties that Elastic Beanstalk doesn't support,
you can still use a configuration file, and specify your settings using
the resources key. The following example sets values to the StorageType and Iops Amazon RDS properties.