# How to Set up RDS PostgreSQL Destination in Daton

## Prerequisites <a href="#chap_gettingstarted.prerequisites.mysql" id="chap_gettingstarted.prerequisites.mysql"></a>

Before you get started, ensure you have the following:

* Active Daton and AWS account
* Administrative user for your AWS account to create or configure a Daton-specific RDS PostgreSQL database

## Task 1: Configure a VPC security connection for Amazon RDS for PostgreSQL

1. Log in to your [RDS dashboard](https://console.aws.amazon.com/rds/home).
2. On the VPC dashboard, choose **Create VPC**.
3. For Resources to create, choose **VPC and more** and perform the following.

   1. Name the VPC.&#x20;
   2. Provide the details according to custom requirements and set the rest to default.

      *You can now visualize the relationships between the VPC resources you've configured.*
   3. When you are finished configuring your VPC, choose Create VPC.

   <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2Fryacu7mQTckEC2zuDx2e%2F2RDS%20postfgres%20desti%20VPC.png?alt=media&#x26;token=bd0e95fb-1a54-4eec-b5b5-ae607dc1deb0" alt="" width="375"><figcaption></figcaption></figure>

   <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FnSLAGwOp5cfofvyPl0xP%2F3RDS%20postfgres%20desti%20VPC.png?alt=media&#x26;token=a28c7fd2-1bba-4615-abc7-642b9ba83001" alt=""><figcaption></figcaption></figure>
4. Your VPC connection is set.&#x20;

   <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FrzrV4lWtKlZATKCKrDRG%2F4RDS%20postfgres%20desti%20VPC.png?alt=media&#x26;token=5876cf77-5c51-483f-9d24-8e1b60a9220b" alt=""><figcaption></figcaption></figure>

## Task 2: Create and Connect to an RDS for PostgreSQL Database Instance&#x20;

1. [Create a Subnet group for the database](#create-a-subnet-group-for-the-database.)
2. [Create a PostgreSQL Database ](#create-a-mysql-database)
3. [Connect to an EC2 Instance ](#connect-to-an-ec2-instance)
4. [Connect to the Database](#connect-to-the-database)

### Create a Subnet group for the database

1. Navigate to the **RDS** in the Amazon Console.
2. Navigate to the **Subnet groups** section and click **Create DB subnet group**.

   <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FDp80OMRegEUrQlr5o1on%2F4RDS%20postfgres%20desti%20Subnet.png?alt=media&#x26;token=7b71e452-28fc-4d6c-adf2-0713394dfe53" alt=""><figcaption></figcaption></figure>
3. On the DB subnet creation page, perform the following:
   * Provide your Subnet group **name** and **description.**

     <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FHH1n7ej1M4hvXUqnXJCv%2F5RDS%20postfgres%20desti%20Subnet.png?alt=media&#x26;token=20a7a6ba-5383-450b-8bdf-297b5447c46f" alt=""><figcaption></figcaption></figure>
   * Select the above-created **VPC identifier.**

     <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2F7X0CfnaOGlC26pdB1vxI%2F6RDS%20postfgres%20desti%20Subnet.png?alt=media&#x26;token=adadd047-3c1f-425e-8bf7-285b1440cfca" alt=""><figcaption></figcaption></figure>
   * Add **Availability zones** and **Subnets,** click **Create**\
     When choosing the Subnets, please ensure to exclusively select the private subnets.

     <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2Fk4vzlnSwNJc7iu7bOjo0%2F7RDS%20postfgres%20desti%20Subnet.png?alt=media&#x26;token=06653d6f-487e-4ade-8c5d-2d3e80d88115" alt=""><figcaption></figcaption></figure>
4. A Subnet group has been created.&#x20;

   <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FkZYWfYcZWZESICrgA0Iq%2F9RDS%20postfgres%20desti%20Subnet.png?alt=media&#x26;token=203bc8cb-77f2-4540-a639-e44799d84802" alt=""><figcaption></figcaption></figure>

### Create a PostgreSQL Database&#x20;

1. In the Amazon RDS navigation pane, choose **Databases**.
2. Choose **Create database** and perform the following:
   1. Select the Engine type as **PostgreSQL** and the Template as **Free tier**.&#x20;

      <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FFJH8Mpskr6DrytUhfqiV%2FPostgredbinstance1.png?alt=media&#x26;token=98ba25fb-d954-4b67-8e6d-5c56e6344052" alt=""><figcaption></figcaption></figure>
   2. Provide a **Name** in the DB instance identifier, a **Master username,** and create a **Master Password.**

      <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FfqI8RUbDecu8u2jxwcPP%2Fdemodatabase.png?alt=media&#x26;token=6a28b4a5-8d4f-49c1-ad69-3b933ecb012d" alt=""><figcaption></figcaption></figure>
   3. In the Instance configuration section, set Burstable classes to **db.t3.micro.**\
      This can be configured as per your specific requirements.

      <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2Fq0bwpk8EkihS2WJTejf8%2Fimage.png?alt=media&#x26;token=b8c816b6-945a-4b7c-a7c6-45c24a1ecaae" alt=""><figcaption></figcaption></figure>
   4. In the Storage section, select the fields as per requirement.\
      It is recommended to set the Storage Type to **General Purpose SSD (gp2).**

      <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2F9Zm25elBUoLYQL2voLhN%2FStorage%20(1).png?alt=media&#x26;token=9ae08450-d26d-4833-b9d0-4e20ef9e4d3d" alt=""><figcaption></figcaption></figure>
   5. In the Connectivity section,&#x20;

      1. Select **Don't connect to an EC2 compute resource**
      2. Select the above-created VPC and DB subnet groups
      3. Set the Public access to **No**
      4. Create a new **VPC security group** for firewall purposes, Name it, and Select an Availability Zone according to your preferences.
      5. Check the **Create an RDS Proxy** checkbox.

      Keep the rest as default or customize according to your requirements.

      <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FOnOGOQpah1hmZuM9JuXN%2FRDS%20MySQL%20Connectivity%20(1).png?alt=media&#x26;token=358edd95-3af9-4134-b662-ba3c2814d565" alt=""><figcaption></figcaption></figure>
   6. Select your **Database Authentication** method, **Monitoring** preferences, and **Additional Configuration** as per your requirements.

      <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FGzoa78ZhxfPf7Q4TMVve%2FRDS%20MySQL%20DBauth%2CMonitor.png?alt=media&#x26;token=321965ff-bb4c-4c79-823c-2aced27c9b0e" alt=""><figcaption></figcaption></figure>
3. Now check your **Estimated Monthly cost** and click on **Create Database**.\
   A new Database will be successfully created.

Please note that you can customize the database according to your specific requirements. To know more follow the link, [Creating an Amazon RDS DB instance](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CreateDBInstance.html).&#x20;

### Connect to an EC2 Instance&#x20;

1. [Launch an EC2 Instance](#create-an-ec2-instance)
2. [Add the EC2 Subnet group to your Database Subnet group](#add-the-ec2-subnet-group-to-your-database-subnet-group)

#### Launch an EC2 Instance&#x20;

1. On the AWS Management Console, go to the Amazon [EC2 console](https://console.aws.amazon.com/ec2/home).
2. Choose EC2 Dashboard, and then choose Launch instance.

   <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FLF2pJXvdwhZhqtYuXbBf%2F2EC2%20insctances.png?alt=media&#x26;token=185b6984-d993-4568-a496-d89c302c5f73" alt="" width="375"><figcaption></figcaption></figure>
3. Provide a Name to the EC2 instance.

   <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2Fi21VykgRvyBkub3ZkQZb%2F3EC2%20insctances.png?alt=media&#x26;token=eb42f6fe-be30-41d9-8a7b-11be6193687d" alt=""><figcaption></figcaption></figure>
4. Under Application and OS Images (Amazon Machine Image), choose an AMI of your choice.

   <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FMPMjnZolHu0oS8DwGhdw%2Fimage.png?alt=media&#x26;token=dd122be6-9194-4b58-a8d0-c4ea20652d14" alt=""><figcaption></figcaption></figure>
5. Select the **t2.micro** option under the Instance type.
6. For the Key pair (login), you have two options. If you already have a key pair, just pick its name. If you want a new key pair, click on Create new key pair. Then, follow the steps in the Create key pair window to make the new key pair.

   <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2F2zgEXdJhiQSOnyfvXmrO%2F5EC2%20insctances.png?alt=media&#x26;token=6e4a499b-f4eb-4ce5-8e10-b6fa732e7582" alt=""><figcaption></figcaption></figure>

   For more information about creating a new key pair, see [Create a key pair](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/get-set-up-for-amazon-ec2.html#create-a-key-pair) in the Amazon EC2 User Guide.
7. In the Network settings section, configure these values while leaving the rest at their default:
   1. Select the previously created **VPC**.
   2. Select one of its **Public Subnet**s.
   3. Set Auto-assign public IP to **Enable**.
   4. Create a **Firewall security group** and Name it.

      <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2F5S0BwlUb1V1HkCXGeomi%2FEC2%20instance%20network%20%20(5).png?alt=media&#x26;token=58c10a88-500d-4398-a532-1d84f2dccd68" alt=""><figcaption></figcaption></figure>
8. Now check the settings of the EC2 instance for configuration or keep them as default and click on **Launch**.\
   A note saying the Instance is successfully launched will appear.\
   \
   This is how your EC2 instance would look like:&#x20;

   <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FilTCjCZCYpZpU4Mmr3Wp%2FStorage%20(5).png?alt=media&#x26;token=6b643820-1651-4560-aa3b-d7d770488707" alt=""><figcaption></figcaption></figure>

#### Add the EC2 Subnet group to your Database Subnet group

Here we edit the inbound subnet groups to connect the EC2 instance with the Database. This step creates a communication tunnel between the EC2 instance and the Database.

1. In the Amazon RDS dashboard, choose the above-created database instance and click on the **VPC security groups** URL under the **Security** section.

   <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FVN17RFBG7knFCMNWskrp%2F1%20Inbound%20security%20groups.png?alt=media&#x26;token=dac95fe9-fe8e-4f54-83ad-8cbe68f1fb48" alt=""><figcaption></figcaption></figure>
2. You will be redirected to the Security Groups page of the dedicated Database instance. Find the **Edit inbound rules** button and click on it.

   <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2F1R9eJurUSDpTJZxDn8LM%2FPostgreSQLEdit%20inbound%20rules%20(1).png?alt=media&#x26;token=2d2fdb7f-0e57-4b1c-a68b-dd9c620d83b0" alt=""><figcaption></figcaption></figure>
3. On the edit page, perform the following:

   1. **Add rule.** Under the Type dropdown, select **PostgreSQL** and select the source as the security groups corresponding to the EC2 instance.
   2. Add another rule. Here, select the Port range as 3306 and add the IP address accordingly.&#x20;

   <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FgaJQS5QKNx3fIB09lyEw%2FPostgreSQLEdit%20inbound%20rules%20(2).png?alt=media&#x26;token=4489bbc7-7be9-4fcb-bf49-af5f247d4b05" alt=""><figcaption></figcaption></figure>

### Connect to the Database

1. Launch a Database Management tool of your choice.&#x20;

2. Create a new PostgreSQL Database connection.

3. In the connection settings:
   1. Provide the **Endpoint** of the above-created Database Instance.\
      You may find the endpoint in the following location:&#x20;

      <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FzKNSVArXdO9b7bYfrXRh%2FStorage%20(3).png?alt=media&#x26;token=a2d8cc5b-d506-4be5-8f57-5dc5f419b72e" alt=""><figcaption></figcaption></figure>
   2. Provide the Master Username and Password of the Database instance.

4. In the SSH tunneling section:
   1. Insert the **Public IPv4 DNS** of the EC2 instance.\
      You may find the Public IPv4 DNS of the EC2 instance in the following location:&#x20;

      <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2Febb2QlysvAdjJ7tkyYX4%2FStorage%20(6).png?alt=media&#x26;token=6582dea1-cd38-4fe5-9879-58d0f35cd49a" alt=""><figcaption></figcaption></figure>
   2. Provide the **Key Pair** used while Launching the EC2 Instance. Remember that, this Key pair is supposedly a .pem file.
   3. Test the SSH connection.

5. Save the Database by clicking on the **Finish** button.\
   Your RDS PostgreSQL Database is successfully configured.

> Note that, you can query in your now created database to create Schemas and Tables as per your requirement.&#x20;

## Task 3: Integrate Amazon RDS for PostgreSQL Database Instance with Daton

1. Log in to your [Daton account](https://daton.sarasanalytics.com/u/integrations-list) and search for RDS PostgreSQL in the list of Destinations, then click **Configure**.
2. Enter the Integration Name and click **Next**:&#x20;

   <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2F6eCbdFGdR8fXXEJfIvKn%2F1RDS%20MySQL.png?alt=media&#x26;token=92e43308-b5c4-4f4f-abf7-0bf83e93baa0" alt=""><figcaption></figcaption></figure>
3. Enter the following credentials to configure your warehouse:

   <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FQQrsfGgdswytN74H42wE%2FRDS%20Postgres%20Daton%20inte%20schema%20(4).png?alt=media&#x26;token=46aa5b37-3c1c-41dd-8788-7657bd6cb6e5" alt=""><figcaption></figcaption></figure>

   1. **RDS PostgreSQL JDBC URL** in the format: **jdbc:postgresql://AmazonRDSPostgreSQL\_Database\_Endpoint:3306/your\_db\_name**
   2. RDS PostgreSQL Master **Username** and **Password**
   3. Set Use Tunnel to **SSH** and provide Proxy Host. \
      Proxy Host is your **Public IPv4 DNS** that can be found in details of the EC2 instance in consideration.
   4. Set the Proxy Port to **22** and the Proxy user to **ec2-user**(Default). You may also create a separate user in the EC2 instance.
4. Select the Schema of your choice.&#x20;

   <figure><img src="https://15515196-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LbJ1eMq5M51cIpU163R%2Fuploads%2FQgAbDiI9e9LZ30UBeirI%2FRDS%20Postgres%20Daton%20inte%20schema%20(2).png?alt=media&#x26;token=092039e1-104a-4b53-afa8-ebaf6f2b0765" alt=""><figcaption></figcaption></figure>

   Now **Submit.** Your warehouse is configured successfully.

> Note:
>
> 1. You may copy the SSH Key that appears at the bottom of the Setup page and add it to you repository for secure Authentication.
> 2. You can query in your created database to create additional Schemas and Tables as per your requirement.&#x20;
