2

I'm using AWS AppSync with Lambda functions as resolvers. Those functions query an RDS Postgres db (with Sequelize).

My problem is that whatever I do, none of my queries are triggered. What's wrong with my code?

import { Context, Callback } from 'aws-lambda';
import * as Sequelize from 'sequelize';

const sequelize = new Sequelize({
  database: process.env.RDS_NAME,
  username: process.env.RDS_USERNAME,
  password: process.env.RDS_PASSWORD,
  host: process.env.RDS_HOST,
  port: 5432,
  dialect: 'postgres',
  pool: { idle: 1000, max: 1 }
});

const options = {
  timestamps: false,
  freezeTableName: true
};

const Node = sequelize.define(
  'node',
  {
    nodeId: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    slug: {
      type: Sequelize.STRING
    }
  },
  options
);

export const getUser = async (
  event: any,
  context: Context,
  callback: Callback
) => {
  context.callbackWaitsForEmptyEventLoop = false;

  Node.findAll({
    where: {}
  })
    .then(nodes => {
      console.log('nodes', nodes);
      callback(null, {
        id: 1,
        name: JSON.stringify(nodes)
      });
    })
    .catch(err => callback(err));
};

I've seen this post but without success. Sequelize Code Not Executing Inside AWS Lambda

1 Answer 1

2

I found the problem. My RDS was in a different security group than the default one. I had to change it to make it work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.