# AWS RDS MySQL

### In this article

> [Prerequisites](#prerequisites)\
> [Create AWS RDS MySQL Integration](#create-aws-rds-mysql-integration)\
> [Next Steps](#next-steps)

Amazon RDS for MySQL is an open-source relational database management service in the cloud. Through AWS RDS MySQL integration, you will be able to integrate with AWS RDS MySQL:

* Database
* Table
* Role

## Prerequisites <a href="#prerequisites" id="prerequisites"></a>

* If you already have AWS Apono connector:
  * Make sure the connector's minimum version is **1.5.3**.
* If you still don't have AWS Apono connector:
  * [Install AWS Account connector on ECS using Terraform.](https://docs.apono.io/docs/aws-environment/apono-connector-for-aws/installing-a-connector-on-aws-ecs-using-terraform)
  * [Install AWS Account connector on ECS using CloudFormation.](https://docs.apono.io/docs/aws-environment/apono-connector-for-aws#aws-account-connector)
  * [Install AWS Organization connector on ECS using Terraform.](https://docs.apono.io/docs/aws-environment/apono-connector-for-aws/installing-a-connector-on-aws-organization-with-terraform)
  * [Install AWS Organization connector on ECS using CloudFormation.](https://docs.apono.io/docs/aws-environment/apono-connector-for-aws#aws-organization-connector-on-the-management-account)
  * [Install AWS Organization connector on EKS using Terraform.](https://docs.apono.io/docs/aws-environment/apono-connector-for-aws/installing-a-connector-on-eks-using-terraform)
* [AWS command-line](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
* [MySQL command-line](https://dev.mysql.com/doc/mysql-shell/8.0/en/mysql-shell-install.html)

## Create AWS RDS MySQL Integration

### Generate Credentials

Create user and grant permissions:

{% hint style="warning" %}
You can use only one authentication option on the RDS instance at a time.
{% endhint %}

{% hint style="info" %}
(MySQL 8.0+) Grant the service account the authority to manage other roles. This enables Apono to create, alter, and drop roles. However, this role does not inherently grant specific database access permissions.
{% endhint %}

{% tabs %}
{% tab title="cli" %}

<details>

<summary>Password Authentication</summary>

With password authentication, your database performs all administration of user accounts. You create users with SQL statements such as `CREATE USER`, with the appropriate clause required by the DB engine for specifying passwords.

1. Get your AWS RDS DB details.

```bash
aws rds describe-db-instances \
  --filters "Name=engine,Values=mysql" \
  --query "*[].[Endpoint.Address,Endpoint.Port]"

mysql -h [Endpoint.Address] -P [Endpoint.Port] -u USER_NAME -p
```

2. Connect RDS MySQL.

```bash
mysql -h [Endpoint.Address] -P [Endpoint.Port] -u USER_NAME -p
```

3. Create a username for the Apono connector. The username is arbitrary and can be set according to your preference.
4. Replace `USER_NAME` and `PASSWORD` with your desired credentials.

```sql
CREATE USER 'USER_NAME'@'%' IDENTIFIED BY 'PASSWORD';
```

5. Grant the necessary permissions to the user.

```sql
GRANT SHOW DATABASES ON *.* TO 'USER_NAME'@'%';
GRANT CREATE USER ON *.* TO 'USER_NAME'@'%';  
GRANT UPDATE ON mysql.* TO 'USER_NAME'@'%';
GRANT PROCESS ON *.* TO 'USER_NAME'@'%';
GRANT SELECT ON *.* TO 'USER_NAME'@'%';
GRANT GRANT OPTION ON *.* TO 'USER_NAME'@'%';
GRANT EXECUTE,DROP,SELECT,ALTER,ALTER ROUTINE,CREATE,CREATE ROUTINE,CREATE TEMPORARY TABLES,CREATE VIEW,DELETE,INDEX,INSERT,TRIGGER,UPDATE ON *.* TO 'USER_NAME'@'%';  
GRANT GRANT OPTION ON *.* TO 'USER_NAME'@'%';
```

`SHOW DATABASES` Allows the user to view all databases in the RDS instance.\
`CREATE USER` Grants the ability to create new users.\
`UPDATE` Permits updates in the MySQL system database, including user privileges.\
`PROCESS` Allows viewing the server's process list, including all executing queries.

6. (MySQL 8.0 and above) Grant the user the authority to manage roles by giving them the ROLE\_ADMIN privilege. Starting with MySQL 8.0, the ROLE\_ADMIN privilege is required to create roles, assign permissions to roles, and grant or revoke roles to or from users. This privilege does not inherently grant any specific database access permissions.

```
GRANT ROLE_ADMIN on *.* to USER_NAME;
```

</details>

<details>

<summary>IAM Authentication</summary>

You can authenticate to your DB instance using AWS Identity and Access Management (IAM) database authentication. With this authentication method, you don't need to use a password when you connect to a DB instance. Instead, you use an authentication token.

1. Get your AWS RDS DB details.

```bash
aws rds describe-db-instances \
  --filters "Name=engine,Values=mysql" \
  --query "*[].[DBInstanceIdentifier,Endpoint.Address,Endpoint.Port]"
```

2. Enable IAM database authentication.

```bash
aws rds modify-db-instance \
    --db-instance-identifier DBInstanceIdentifier \
    --apply-immediately \
    --enable-iam-database-authentication
```

3. Connect RDS MySQL.

```bash
mysql -h [Endpoint.Address] -P [Endpoint.Port] -u USER_NAME -p
```

4. Create a username for the Apono connector. The username is arbitrary and can be set according to your preference.
5. Replace `USER_NAME` with your desired credentials.

```sql
CREATE USER USER_NAME IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS';
```

6. Grant the necessary permissions to the user.

```sql
GRANT SHOW DATABASES ON *.* TO 'USER_NAME'@'%';
GRANT CREATE USER ON *.* TO 'USER_NAME'@'%';  
GRANT UPDATE ON mysql.* TO 'USER_NAME'@'%';
GRANT PROCESS ON *.* TO 'USER_NAME'@'%';
GRANT SELECT ON *.* TO 'USER_NAME'@'%';
GRANT EXECUTE,DROP,SELECT,ALTER,ALTER ROUTINE,CREATE,CREATE ROUTINE,CREATE TEMPORARY TABLES,CREATE VIEW,DELETE,INDEX,INSERT,TRIGGER,UPDATE ON *.* TO 'USER_NAME'@'%';  
GRANT GRANT OPTION ON *.* TO 'USER_NAME'@'%';
```

`SHOW DATABASES` Allows the user to view all databases in the RDS instance.\
`CREATE USER` Grants the ability to create new users.\
`UPDATE` Permits updates in the MySQL system database, including user privileges.\
`PROCESS` Allows viewing the server's process list, including all executing queries.

7. Add this policy to the connector role:

```json
{ "Version": "2012-10-17", "Statement": [ { "Action": "rds-db:connect", "Resource": "arn:aws:rds-db:::dbuser:*/USER_NAME", "Effect": "Allow" } ] }
```

8. To allow a user or role to connect to your DB instance, create the following IAM policy and attach it to your identity center permissions set or role.

```bash
aws iam create-policy --policy-name RDSConnectPolicy --policy-document '{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "rds-db:connect"
            ],
            "Resource": [
                "arn:aws:rds-db:*:*:dbuser:*/${SAML:sub}"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "rds:DescribeDBInstances"
            ],
            "Resource": [
                "arn:aws:rds:*:*:db:*"
            ]
        }
    ]
}'
```

</details>
{% endtab %}

{% tab title="cmd" %}

<details>

<summary>Password Authentication</summary>

With password authentication, your database performs all administration of user accounts. You create users with SQL statements such as `CREATE USER`, with the appropriate clause required by the DB engine for specifying passwords.

1. Get your AWS RDS DB details.

```cmd
aws rds describe-db-instances \
  --filters "Name=engine,Values=mysql" \
  --query "*[].[Endpoint.Address,Endpoint.Port]"

mysql -h [Endpoint.Address] -P [Endpoint.Port] -u USER_NAME -p
```

2. Connect RDS MySQL.

```cmd
mysql -h [Endpoint.Address] -P [Endpoint.Port] -u USER_NAME -p
```

3. Create a username for the Apono connector. The username is arbitrary and can be set according to your preference.
4. Replace `USER_NAME` and `PASSWORD` with your desired credentials.

```sql
CREATE USER 'USER_NAME'@'%' IDENTIFIED BY 'PASSWORD';
```

4. Grant the necessary permissions to the user.

```sql
GRANT SHOW DATABASES ON *.* TO 'USER_NAME'@'%';
GRANT CREATE USER ON *.* TO 'USER_NAME'@'%';  
GRANT UPDATE ON mysql.* TO 'USER_NAME'@'%';
GRANT PROCESS ON *.* TO 'USER_NAME'@'%';
GRANT SELECT ON *.* TO 'USER_NAME'@'%';
GRANT EXECUTE,DROP,SELECT,ALTER,ALTER ROUTINE,CREATE,CREATE ROUTINE,CREATE TEMPORARY TABLES,CREATE VIEW,DELETE,INDEX,INSERT,TRIGGER,UPDATE ON *.* TO 'USER_NAME'@'%';  
GRANT GRANT OPTION ON *.* TO 'USER_NAME'@'%';
```

`SHOW DATABASES` Allows the user to view all databases in the RDS instance.\
`CREATE USER` Grants the ability to create new users.\
`UPDATE` Permits updates in the MySQL system database, including user privileges.\
`PROCESS` Allows viewing the server's process list, including all executing queries.

5. (MySQL 8.0 and above) Grant the user the authority to manage roles by giving them the ROLE\_ADMIN privilege. Starting with MySQL 8.0, the ROLE\_ADMIN privilege is required to create roles, assign permissions to roles, and grant or revoke roles to or from users. This privilege does not inherently grant any specific database access permissions.

```
GRANT ROLE_ADMIN on *.* to USER_NAME;
```

</details>

<details>

<summary>IAM Authentication</summary>

You can authenticate to your DB instance using AWS Identity and Access Management (IAM) database authentication. With this authentication method, you don't need to use a password when you connect to a DB instance. Instead, you use an authentication token.

1. Get your AWS RDS DB details.

```cmd
aws rds describe-db-instances \
  --filters "Name=engine,Values=mysql" \
  --query "*[].[DBInstanceIdentifier,Endpoint.Address,Endpoint.Port]"
```

2. Enable IAM database authentication.

```cmd
aws rds modify-db-instance \
    --db-instance-identifier DBInstanceIdentifier \
    --apply-immediately \
    --enable-iam-database-authentication
```

3. Connect RDS MySQL.

```cmd
mysql -h [Endpoint.Address] -P [Endpoint.Port] -u USER_NAME -p
```

4. Create a username for the Apono connector. The username is arbitrary and can be set according to your preference.
5. Replace `USER_NAME` with your desired credentials.

```sql
CREATE USER USER_NAME IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS';
```

6. Grant the necessary permissions to the user.

```sql
GRANT SHOW DATABASES ON *.* TO 'USER_NAME'@'%';
GRANT CREATE USER ON *.* TO 'USER_NAME'@'%';  
GRANT UPDATE ON mysql.* TO 'USER_NAME'@'%';
GRANT PROCESS ON *.* TO 'USER_NAME'@'%';
GRANT SELECT ON *.* TO 'USER_NAME'@'%';
GRANT EXECUTE,DROP,SELECT,ALTER,ALTER ROUTINE,CREATE,CREATE ROUTINE,CREATE TEMPORARY TABLES,CREATE VIEW,DELETE,INDEX,INSERT,TRIGGER,UPDATE ON *.* TO 'USER_NAME'@'%';  
GRANT GRANT OPTION ON *.* TO 'USER_NAME'@'%';
```

`SHOW DATABASES` Allows the user to view all databases in the RDS instance.\
`CREATE USER` Grants the ability to create new users.\
`UPDATE` Permits updates in the MySQL system database, including user privileges.\
`PROCESS` Allows viewing the server's process list, including all executing queries.

7. Add this policy to the connector role:

```json
{ "Version": "2012-10-17", "Statement": [ { "Action": "rds-db:connect", "Resource": "arn:aws:rds-db:::dbuser:*/USER_NAME", "Effect": "Allow" } ] }
```

8. To allow a user or role to connect to your DB instance, create the following IAM policy and attach it to your identity center permissions set or role.

```json
aws iam create-policy --policy-name RDSConnectPolicy --policy-document '{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "rds-db:connect"
            ],
            "Resource": [
                "arn:aws:rds-db:*:*:dbuser:*/${SAML:sub}"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "rds:DescribeDBInstances"
            ],
            "Resource": [
                "arn:aws:rds:*:*:db:*"
            ]
        }
    ]
}'
```

</details>
{% endtab %}

{% tab title="console" %}

<details>

<summary>Password Authentication</summary>

With password authentication, your database performs all administration of user accounts. You create users with SQL statements such as `CREATE USER`, with the appropriate clause required by the DB engine for specifying passwords.

1. Sign in to the AWS Management Console and open the Amazon RDS console [Amazon RDS console](https://console.aws.amazon.com/rds/) , and choose your DB instance.
2. Copy the following details:
   * **Endpoint**: The DNS name of the DB instance.
   * **Port**: The port number on which the DB instance accepts connections.
3. Connect to the DB instance using your SQL client using the copied details.
4. Create a user for the Apono connector. Replace `USER_NAME` and `PASSWORD` with your desired credentials.

<pre class="language-sql"><code class="lang-sql"><strong>CREATE USER 'USER_NAME'@'%' IDENTIFIED BY 'PASSWORD';
</strong></code></pre>

5. Grant the necessary permissions to the user.

```sql
GRANT SHOW DATABASES ON *.* TO 'USER_NAME'@'%';
GRANT CREATE USER ON *.* TO 'USER_NAME'@'%';  
GRANT UPDATE ON mysql.* TO 'USER_NAME'@'%';
GRANT PROCESS ON *.* TO 'USER_NAME'@'%';
GRANT SELECT ON *.* TO 'USER_NAME'@'%';
GRANT EXECUTE,DROP,SELECT,ALTER,ALTER ROUTINE,CREATE,CREATE ROUTINE,CREATE TEMPORARY TABLES,CREATE VIEW,DELETE,INDEX,INSERT,TRIGGER,UPDATE ON *.* TO 'USER_NAME'@'%';  
GRANT GRANT OPTION ON *.* TO 'USER_NAME'@'%';
```

`SHOW DATABASES` Allows the user to view all databases in the RDS instance.\
`CREATE USER` Grants the ability to create new users.\
`UPDATE` Permits updates in the MySQL system database, including user privileges.\
`PROCESS` Allows viewing the server's process list, including all executing queries.

6. (MySQL 8.0 and above) Grant the user the authority to manage roles by giving them the ROLE\_ADMIN privilege. Starting with MySQL 8.0, the ROLE\_ADMIN privilege is required to create roles, assign permissions to roles, and grant or revoke roles to or from users. This privilege does not inherently grant any specific database access permissions.

```
GRANT ROLE_ADMIN on *.* to USER_NAME;
```

</details>

<details>

<summary>IAM Authentication</summary>

You can authenticate to your DB instance using AWS Identity and Access Management (IAM) database authentication. With this authentication method, you don't need to use a password when you connect to a DB instance. Instead, you use an authentication token.

1. Enable IAM database authentication
   1. Open the [Amazon RDS console](https://console.aws.amazon.com/rds/).
   2. In the navigation pane, choose Databases.
   3. Choose the DB instance that you want to modify.
   4. Make sure that the DB instance is compatible with IAM authentication. Check the compatibility requirements in Region and version availability.
   5. Choose Modify.
   6. In the Database authentication section, choose Password and IAM database authentication to enable IAM database authentication.
   7. Choose Password authentication or Password and Kerberos authentication to disable IAM authentication.
   8. Choose Continue.
   9. To apply the changes immediately, choose Immediately in the Scheduling of modifications section.
   10. Choose Modify DB instance.
2. Copy the following RDS SQL details:

* **Endpoint**: The DNS name of the DB instance.
* **Port**: The port number on which the DB instance accepts connections.

3. Connect to the DB instance using your SQL client using the copied details.
4. Create a username for the Apono connector. The username is arbitrary and can be set according to your preference.
5. Replace `USER_NAME` with your desired credentials.

```sql
CREATE USER USER_NAME IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS';
```

5. Grant the necessary permissions to the user.

```sql
GRANT SHOW DATABASES ON *.* TO 'USER_NAME'@'%';
GRANT CREATE USER ON *.* TO 'USER_NAME'@'%';  
GRANT UPDATE ON mysql.* TO 'USER_NAME'@'%';
GRANT PROCESS ON *.* TO 'USER_NAME'@'%';
GRANT SELECT ON *.* TO 'USER_NAME'@'%';
GRANT EXECUTE,DROP,SELECT,ALTER,ALTER ROUTINE,CREATE,CREATE ROUTINE,CREATE TEMPORARY TABLES,CREATE VIEW,DELETE,INDEX,INSERT,TRIGGER,UPDATE ON *.* TO 'USER_NAME'@'%';  
GRANT GRANT OPTION ON *.* TO 'USER_NAME'@'%';
```

`SHOW DATABASES` Allows the user to view all databases in the RDS instance.\
`CREATE USER` Grants the ability to create new users.\
`UPDATE` Permits updates in the MySQL system database, including user privileges.\
`PROCESS` Allows viewing the server's process list, including all executing queries.

6. Add this policy to the connector role:

```json
{ "Version": "2012-10-17", "Statement": [ { "Action": "rds-db:connect", "Resource": "arn:aws:rds-db:::dbuser:*/USER_NAME", "Effect": "Allow" } ] }
```

7. To allow a user or role to connect to your DB instance, create the following IAM policy and attach it to your identity center permissions set or role.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
        "Action": [
          "rds-db:connect"
        ],
      "Resource": [
        "arn:aws:rds-db:*:*:dbuser:*/${SAML:sub}"
      ]
    },
    {
      "Effect": "Allow",
        "Action": [
          "rds:DescribeDBInstances"
        ],
        "Resource": [
          "arn:aws:rds:*:*:db:*"
        ]
      }
  ]
}
```

</details>
{% endtab %}
{% endtabs %}

### Create Integration in Apono

1. In the [Apono admin console](https://app.apono.io), go to the **Integrations** page and click the **Add Integration** button in the top-left side, or press on the **Catalog** blade.
2. In the **Catalog** page search for and select **AWS RDS MySQL**.
3. In **Discovery** step, select one or multiple AWS RDS MySQL resource types for Apono to discover.
4. In **Apono connector** step, select the connector with the required permissions to be used with your AWS RDS MySQL.
5. In **Integration config** step, provide the following information about your AWS RDS MySQL:

| Variable                                       | Value                                                                                                                                                 | Required |
| ---------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| Integration Name                               | The integration name.                                                                                                                                 | Yes      |
| Auth Type                                      | The authentication method for connecting to an AWS RDS instance, with options for password (username and password) or iam (IAM-based authentication). | Yes      |
| Region                                         | AWS region where the RDS instance is located.                                                                                                         | Yes      |
| Instance ID                                    | The unique identifier of the AWS RDS instance.                                                                                                        | Yes      |
| Credentials rotation period (in days)          | i.e.: 90                                                                                                                                              | No       |
| User cleanup after access is revoked (in days) | i.e.: 90                                                                                                                                              | No       |

6. In [**Secret Store**](https://docs.apono.io/docs/connectors-and-secrets/apono-integration-secret) step, provide the connector credentials using one of the following secret store options:
   * [AWS](https://docs.apono.io/docs/connectors-and-secrets/apono-integration-secret#aws-secret)
   * [KUBERNETES](https://docs.apono.io/docs/connectors-and-secrets/apono-integration-secret#kubernetes-secret)
   * [APONO](https://docs.apono.io/docs/connectors-and-secrets/apono-integration-secret#apono-secret)
   * [HASHICORP](https://docs.apono.io/docs/connectors-and-secrets/apono-integration-secret#hashicorp-secret)

{% hint style="info" %}
When using IAM authentication, **a secret does not need to be created**. The service account and its permissions are managed through IAM roles and policies. The service account is used to authenticate the MySQL instance instead of a secret.

For the AWS RDS MySQL integration, use the following secret format:\
`username:<The database username>`\
`password:<The user password>`
{% endhint %}

7. (Optional) In **Get more with Apono** step, you can set up the following:

<table><thead><tr><th width="207">Setting</th><th>Description</th></tr></thead><tbody><tr><td><strong>Credential Rotation</strong></td><td>(Optional) Number of days after which the database credentials must be rotated<br><br>Learn more about the <a href="../../architecture-and-security/credentials-rotation-policy">Credentials Rotation Policy</a>.</td></tr><tr><td><strong>User cleanup after access is revoked (in days)</strong></td><td><p>(Optional) Defines the number of days after access has been revoked that the user should be deleted</p><p><br>Learn more about <a href="../../architecture-and-security/periodic-user-cleanup-and-deletion">Periodic User Cleanup &#x26; Deletion</a>.</p></td></tr><tr><td><strong>Custom Access Details</strong></td><td>(Optional) Instructions explaining how to access this integration's resources<br><br>Upon accessing an integration, a message with these instructions will be displayed to end users in the User Portal. The message may include up to <strong>400 characters</strong>.<br><br>To view the message as it appears to end users, click <strong>Preview</strong>.</td></tr><tr><td><strong>Integration Owner</strong></td><td><p>(Optional) Fallback approver if no <a href="../../access-flows/dynamic-access-management/resource-and-integration-owners">resource owner</a> is found<br><br>Follow these steps to define one or several integration owners:</p><ol><li>From the <strong>Attribute</strong> dropdown menu, select <strong>User</strong> or <strong>Group</strong> under the relevant identity provider (IdP) platform.</li><li>From the <strong>Value</strong> dropdown menu, select one or multiple users or groups.</li></ol><p><br><strong>NOTE</strong>: When <strong>Resource Owner</strong> is defined, an <strong>Integration Owner</strong> must be defined.</p></td></tr><tr><td><strong>Resource Owner</strong></td><td><p>(Optional) Group or role responsible for managing access approvals or rejections for the resource<br><br>Follow these steps to define one or several <a href="../../access-flows/dynamic-access-management/resource-and-integration-owners">resource owners</a>:</p><ol><li>Enter a <strong>Key name</strong>. This value is the name of the tag created in your cloud environment.</li><li>From the <strong>Attribute</strong> dropdown menu, select an attribute under the IdP platform to which the key name is associated.<br><br>Apono will use the value associated with the key (tag) to identify the resource owner. When you update the membership of the group or role in your IdP platform, this change is also reflected in Apono.</li></ol><p><br><strong>NOTE</strong>: When this setting is defined, an <strong>Integration Owner</strong> must also be defined.</p></td></tr></tbody></table>

## Next Steps

<table data-card-size="large" data-view="cards"><thead><tr><th></th></tr></thead><tbody><tr><td><a href="https://docs.apono.io/docs/access-flows/access-flows">Create Integration Access Flow</a></td></tr></tbody></table>
