Skip to content

Instantly share code, notes, and snippets.

@ryanjohnston
Last active September 3, 2019 17:06
Show Gist options
  • Save ryanjohnston/129d36db84d01acee4da6b1286417772 to your computer and use it in GitHub Desktop.
Save ryanjohnston/129d36db84d01acee4da6b1286417772 to your computer and use it in GitHub Desktop.
[aws] Samples

Connect to Serverless RDS from an EC2 Instance.

Note: Both the EC2 Instance and the Serverless RDS cluster must be in the same AWS Virtual Private Cloud (VPC) for this to work*

For this example, new EC2 instances are deployed in the 'VPC Security' group. AWS Serverless RDS setup the other security group when the database was created. Follow these steps to allow your EC2 instances to connect directly to the Serverless RDS cluster.

Change the following sample ID's to match your AWS setup

VPC Security Group: sg-0c1b4b-example RDS Serverless Security Group: sg-025faf-example

  1. Select the Database security Group
  2. Select ‘Inbound’ rules.
  3. Select ‘Edit rules’
  4. Select ‘Add Rule’
  5. Select ‘Mysql/Aurora’ for the type.
  6. For source, enter the security group id of the VPN group

You will now be able to connect directly to the Serverless database while logged into an EC2 instance inside your VPC.

Disable DeleteOnTermination for EBS Volumes

This property can only be changed via the AWS CLI. You can find the DeviceName within the EC2 online web console.

Create JSON file like the following and name it ec2.block.mappings.json

[
  {
    "DeviceName": "/dev/sda1",
    "Ebs": {
      "DeleteOnTermination": false
    }
  }
]

Run the following CLI command to disable deletion on EC2 instance termination:

aws ec2 modify-instance-attribute --instance-id [your instance ID] --block-device-mappings file://ec2.block.mappings.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment