Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

266
Views
Twilio function writing to aws rds postgres error

I wrote the below twilio function to store incoming messages into a postgres database in RDS on AWS. I'm getting a 504 timeout error. Details of how I am running:

  • I'm running this by deploying the function to twilio & adding it as a widget to a twilio studio flow.
  • My postgres database is in RDS. It is publicly accessible and I'm able to access it from my local machine (I added a security rule for My IP. I'm not sure if I need to add a rule for Twilio, I could find a specific IP they would be on.)
  • This is my personal computer, so it shouldn't have any extra firewalls. Any thoughts would be appreciated!

I'm not sure if:

  1. There is something wrong with the below script or
  2. AWS/RDS database is refusing connection. I don't know how to properly update my security rules to allow traffic from twilio.
const{Client} = require("pg");

exports.handler = async function(context, event, callback) {
  console.log("HELLO")
  // Not sure what the below does
  // context.callbackWaitsForEmptyEventLoop = false;
  // Add database config
  const client = new Client({
    host: context.host,
    port: context.port,
    user: context.user,
    password: context.password,
    database: context.database
  });

  // Try actually connecting to the database
  try {
    await client.connect();
    console.log("connected successfully");
    const user = ["12222222222", "2022-07-10T00:22:10Z", '{"question1": {"question": "How are you?", "answer": "great"}}'];

    // Try to actually store the data
    await client.query("INSERT INTO text_responses (phone_number, datetime, response) VALUES ($1, $2, $3::jsonb)", user);
    await client.end();
    console.log("Executed!");
    callback(null, "12222222222");
  } catch (e) {
    console.log(`error: ${e}`);
    callback(e);
  }
};

Twilio error

Outbound HTTP Request Failed: Request URL: https://example-2039-dev.twil.io/log-sms-db
Request Method: POST
Response Status Code: 502
Response Content Type:

Error - 81016

Outgoing HTTP request failed

The outgoing HTTP request from a Studio widget failed.

Possible Causes

The URL you are requesting is incorrect
The response is badly formed
The URL returned a 4xx or 5xx error code
Possible Solutions

Make sure the request results in a response code 2xx or 3xx
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!