Basically I'm having an issue with IAM roles and connecting to a RDS MySQL database using PHP and PDO as the connection method;
I'm going to leave out alot of information for simplicity; Lets assume I have created the IAM role correctly and assigned it correct.
Here is the error I'm getting ( Very Generic I know )
"db_connection": {
"error": "Database connection failed",
"message": "SQLSTATE[HY000] [1045] Access denied for user 'jane_doe'@'****' (using password: NO)"
},
Here is the connection credentials im passing;
"connection_credentials_debug": {
"host": "****",
"port": "3306",
"dbname": "data",
"dbUsername": "jane_doe",
"authToken": "Action=connect&DBUser=jane_doe&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIATQTFLNFMMISRAKAT%2F20230803%2Feu-west-2%2Frds-db%2Faws4_request&X-Amz-Date=20230803T014513Z&X-Amz-SignedHeaders=&X-Amz-Expires=900&X-Amz-Signature=ab6498cd78a0158c1bf0adcc2a482152cb7dba944cd6147d20ad396a6b22c419"
}
I think the issue is with the authToken; I think I need to do something with that auth token before I pass it or it could be a issue with the placement of the auth token in the pdo connect.
Here is the code I'm using;
$generator = new AuthTokenGenerator(new Aws\Credentials\Credentials(
'****', // AWS access key
'****' // AWS secret key
));
$dbHostname = '****';
$region = 'eu-west-2';
$dbUsername = 'jane_doe';
$authToken = $generator->createToken($dbHostname, $region, $dbUsername);
try {
$dbConnection = new PDO("mysql:host={$dbHostname};port=3306;dbname=data", $dbUsername, $authToken);
// Database connection successful
$response = "Database connection successful";
} catch (PDOException $e) {
// Database connection failed
$response = [
'error' => 'Database connection failed',
'message' => $e->getMessage(),
];
}
I am looking for a successful connection.