Connect your EC2 instance to an Amazon resource
After you launch an instance, you can connect it to one or more Amazon resources.
This section describes how to automatically connect an Amazon EC2 instance to an Amazon RDS database.
Automatically connect an EC2 instance to an RDS database
You can use the automatic connection functionality in the Amazon EC2 console to quickly connect one or more EC2 instances to an RDS database to allow traffic between them.
For more information, see How the connection is automatically configured. For a detailed walkthrough, which includes other ways to connect an EC2 instance and an RDS database, see Tutorial: Connect an Amazon EC2 instance to an Amazon RDS database.
Topics
Costs
While there is no charge to automatically connect your EC2 instance to an RDS database, you
are charged for the underlying services. Data transfer fees will apply if your EC2
instance and RDS database are in different Availability Zones. For information about
data transfer fees, see Data Transfer
Prerequisites
Before you can automatically connect an EC2 instance to an RDS database, check the following:
-
The EC2 instances must be in the Running state. You can't connect an EC2 instance if it's in another state.
-
The EC2 instances and the RDS database must be in the same virtual private cloud (VPC). The automatic connection feature is not supported if an EC2 instance and RDS database are in different VPCs.
Automatically connect an instance and a database
You can automatically connect an EC2 instance to an RDS database immediately after you've launched your instance, or later.
Automatically connect immediately after launch
Use the following steps to automatically connect an EC2 instance to an RDS database immediately after you've launched the EC2 instance.
To view an animation of these steps, see View an animation: Automatically connect a newly-launched EC2 instance to an RDS database.
To automatically connect a newly-launched EC2 instance to an RDS database using the EC2 console
Open the Amazon EC2 console at https://console.amazonaws.cn/ec2/
. -
From the console dashboard, choose Launch instances, and then follow the steps to launch an instance.
-
On the instance launch confirmation page, choose Connect an RDS database.
-
In the Connect RDS Database dialog box, do the following:
-
For Database role, choose either Cluster or Instance.
-
For RDS database, select a database to connect to.
Note
The EC2 instances and the RDS database must be in the same VPC in order to connect to each other.
-
Choose Connect.
-

Automatically connect an existing instance
Use the following steps to automatically connect an existing EC2 instance to an RDS database.
To view an animation of these steps, see View an animation: Automatically connect an existing EC2 instance to an RDS database.
To automatically connect an existing EC2 instance to an RDS database using the EC2 console
Open the Amazon EC2 console at https://console.amazonaws.cn/ec2/
. -
In the navigation pane, choose Instances.
-
Select one or more EC2 instances to connect to an RDS database, and then choose Actions, Networking, Connect RDS database.
If Connect RDS database is not available, check that the EC2 instances are in the Running state and that they are in the same VPC.
-
In the Connect RDS Database dialog box, do the following:
-
For Database role, choose either Cluster or Instance.
-
For RDS database, select a database to connect to.
Note
The EC2 instances and the RDS database must be in the same VPC in order to connect to each other.
-
Choose Connect.
-

For information about how to use the Amazon RDS console to automatically connect an EC2 instance to an RDS database, see Configure automatic network connectivity with an EC2 instance in the Amazon RDS User Guide.
How the connection is automatically configured
When you use the EC2 console to automatically configure the connection between an EC2 instance and an RDS database to allow traffic between them, the connection is configured by security groups.
The security groups are automatically created and added to the EC2 instance and RDS database, as follows:
-
Amazon EC2 creates a security group called ec2-rds-
x
and adds it to the EC2 instance. It has one outbound rule that allows traffic to the database by specifying rds-ec2-x
(the database security group) as its destination. -
Amazon RDS creates a security group called rds-ec2-
x
and adds it to the database. It has one inbound rule that allows traffic from the EC2 instance by specifying ec2-rds-x
(the EC2 instance security group) as its source.
The security groups reference each other as the destination and source, and only allow
traffic on the database port. You can reuse these security groups so that any
database with the rds-ec2-x
security
group can talk to any EC2 instance with the
ec2-rds-x
security
group.
The security group names follow a pattern. For the security groups created by Amazon EC2,
the pattern is ec2-rds-x
, and for
the security groups created by Amazon RDS, the pattern is
rds-ec2-x
.
x
is a number, which
increases by 1 each time a new security group is automatically created.