This is my Google Cloud Function:
async function getPSQLdata() {
const pg = require('pg');
var pgConfig = {
user: 'postgres',
password: '[MY PASSWORD]',
database: '[MY DB NAME]',
host: '[PUBLIC IP ADDRESS OF DB INSTANCE]'
};
var pgPool;
if (!pgPool) {
pgPool = new pg.Pool(pgConfig);
}
const scores = await pgPool
.query("SELECT * from table")
.then(res => console.log(res.rows[0]))
.catch(e => console.error(e.stack));
}
exports.dailyFill = async function main() {
await getPSQLdata();
};
Google Cloud Logging says: "Function execution took 60003 ms, finished with status: 'timeout'".
What I have tried so far:
- I have enabled the Cloud SQL Admin API within the GCP project
- I have enabled the Cloud SQL API within the GCP project
- I have added the Google Cloud Function service account to the IAM as the roles "Cloud SQL Client" and "Project Editor"
getPSQLdata
toreturn pgPool.query("SELECT * from table").then(res =>console.log(res.rows[0])).catch(e => console.error(e.stack));
and export this function as inexports.dailyFill = getPSQLdata
– Methkal Khalawi