Reputation: 795
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
Upvotes: 2
Views: 1148
Reputation: 795
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.
Upvotes: 2