ℹ️ Information: Security groups act as virtual firewalls for your Amazon EC2 instances to control inbound and outbound traffic. For our RDS deployment, we need to create a security group for EC2 instances that will connect to our database.
Follow these steps to create a security group with the necessary ports:
In the EC2 navigation pane, scroll down to Security section. Click Security Groups.
Click the Create security group button.

In the Basic details section:
ec2-sgSecurity group for EC2 instances connecting to RDS
In the Inbound rules section, click Add rule to configure the following access:
🔒 Security Note: For production environments, restrict the source IP addresses for SSH access to only trusted IP ranges rather than allowing access from anywhere (0.0.0.0/0).

Review your settings and click Create security group.

Once created, the new security group appears in your security groups list. Note the Security Group ID as you’ll need it when launching EC2 instances.

💡 Pro Tip: You can modify security group rules at any time, and the changes take effect immediately. This allows you to adjust access controls as your application requirements evolve.
⚠️ Warning: Security groups are stateful — if you allow inbound traffic on a specific port, the corresponding outbound response traffic is automatically allowed, regardless of outbound rules.
ℹ️ Information: Security groups act as virtual firewalls for your Amazon RDS instances, controlling inbound and outbound traffic at the instance level. Each security group contains a set of rules that filter traffic based on protocol, port, and source or destination.
Follow these steps to create a dedicated security group for your Amazon RDS database instance:
In the EC2 navigation pane, scroll down to Security section. Click Security Groups.

In the Basic details section:
rds-sgSecurity group for RDS MySQL database instances
Configure Inbound rules to control which traffic sources can access your database:
🔒 Security Note: Specifying the EC2 security group as the source rather than an IP range ensures only instances with that security group can connect to your database, enhancing security.


💡 Pro Tip: You can modify security group rules at any time, and the changes take effect immediately. This allows you to adjust access controls as your application requirements evolve.
⚠️ Warning: It is a best practice to use separate security groups for your RDS instances and EC2 instances. This separation provides better security isolation and makes it easier to manage permissions for each resource type independently.
⚠️ Warning: Security groups are stateful — if you allow inbound traffic on a specific port, the corresponding outbound response traffic is automatically allowed, regardless of outbound rules.