CREATE USER [계정명] IDENTIFIED WITH AWSAuthenticationPlugin as 'RDS';
GRANT [권한] TABLES ON [db명].* TO [계정명];
# 예시
CREATE USER tmp_iam_conn_test IDENTIFIED WITH AWSAuthenticationPlugin as 'RDS';
GRANT SELECT TABLES ON test.* TO tmp_iam_conn_test;
# 모든 권한을 부여하고자 하는 경우 아래 명령어 사용
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, PROCESS, REFERENCES, INDEX, ALTER, SHOW DATABASES, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER TABLES ON [db명].* TO [계정명];
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"rds-db:connect"
],
"Resource": [
"arn:aws:rds-db:[리전]:[계정ID]:dbuser:[RDS 리소스ID]/[계정명]"
]
}
]
}
# 예시
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"rds-db:connect"
],
"Resource": [
"arn:aws:rds-db:ap-northeast-2:123456789012:dbuser:db-QPUA7ZC5DG93NQLBU5NCX6XXZZ/tmp_iam_conn_test"
]
}
]
}
sudo mkdir -p /var/mysql-certs/
cd /var/mysql-certs/
sudo curl -O https://s3.amazonaws.com/rds-downloads/rds-combined-ca-bundle.pem
TOKEN="$(aws rds generate-db-auth-token --hostname [RDS 엔드포인트] --port 3306 --username [계정명])"
# 예시
TOKEN="$(aws rds generate-db-auth-token --hostname tmp-iam-conn-test-db.cgxnhqxrcq8b.ap-northeast-2.rds.amazonaws.com --port 3306 --username tmp_iam_conn_test)"
mysql --host=[RDS 엔드포인트] \
--port=3306 \
--user=[계정명] \
--ssl-ca=/var/mysql-certs/rds-combined-ca-bundle.pem \
--enable-cleartext-plugin \
--password="$TOKEN"
# 예시
mysql --host=tmp-iam-conn-test-db.cgxnhqxrcq8b.ap-northeast-2.rds.amazonaws.com \
--port=3306 \
--user=tmp_iam_conn_test \
--ssl-ca=/var/mysql-certs/rds-combined-ca-bundle.pem \
--enable-cleartext-plugin \
--password="$TOKEN"