Reputation: 21
So, I am running into what seems to be a roles issue when creating a Lambda function to access my RDS database. Whenever I run my lambda I hit a timeout after about 57 seconds, and when I go to the RDS database in configuration I get the following warning: Function execution role: LambdaTest
does not have the required permission for RDS proxy: proxy-xxx. I have the following permissions attached to that role: AWSLambdaSQSQueueExecutionRole, and AWSLambdaVPCAccessExecutionRole. I am also including the code for the lambda if there is something wrong there, any help would be appreciated.
var mysql = require('mysql');
const dbConfig = {
host: 'hostaddress',
user: 'user',
password: 'password',
port: XXXX,
database: 'database',
debug: false,
};
const connection = mysql.createConnection(dbConfig);
exports.handler = async (event, context) => {
try {
connection.connect();
const query = 'SELECT * FROM Therapists';
const results = await executeQuery(query);
connection.end();
return {
statusCode: 200,
body: JSON.stringify(results)
};
} catch (err) {
return {
statusCode: 500,
error: err.message
};
}
}
function executeQuery(query) {
return new Promise((resolve, reject) => {
connection.query(query, (error, results) => {
if (error) {
reject(error);
} else {
resolve(results);
}
});
});
}
I have tried adding more permissions, and reviewed that the RDS, RDS Proxy and the Lambda are all on the same VPC, and share the same security groups, and subnets. But, so far nothing is working.
Upvotes: 2
Views: 299
Reputation: 1853
I had the Timeout problem. Figured out the database security group did not allow connection from lambda security group.
To solve "Connect to RDS" problem, Add "rds-db:connect"
policy Action to your lambda role
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"rds-db:connect"
],
"Resource": [
"arn:aws:rds-db:ap-northeast-1:AWS-Account-ID:dbuser:prx-ABCDEFGHIJKL01234/proxy_user"
]
}
]
}
Upvotes: 0