Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

265
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda