【问题标题】:RDS connection with Sequelize is never called in Lambda function从未在 Lambda 函数中调用与 Sequelize 的 RDS 连接
【发布时间】:2018-10-05 06:10:40
【问题描述】:

我将 AWS AppSync 与 Lambda 函数一起用作解析程序。 这些函数查询 RDS Postgres 数据库(使用 Sequelize)。

我的问题是,无论我做什么,我的查询都不会被触发。我的代码有什么问题?

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));
};

我看过这篇文章,但没有成功。 Sequelize Code Not Executing Inside AWS Lambda

【问题讨论】:

    标签: lambda aws-lambda sequelize.js aws-appsync


    【解决方案1】:

    我发现了问题。我的 RDS 位于与默认安全组不同的安全组中。我必须对其进行更改才能使其正常工作。

    【讨论】:

      猜你喜欢
      • 2019-10-14
      • 1970-01-01
      • 2016-07-24
      • 1970-01-01
      • 2021-03-17
      • 2019-10-28
      • 2020-01-23
      • 2017-02-17
      • 2017-09-13
      相关资源
      最近更新 更多