Use sequelize.js ORM library with servereless

I posted a detailed version including code here (https://stackoverflow.com/questions/48554917/getting-sequelize-js-library-to-work-on-amazon-lambda), but the basic issue is that mysql2 won’t seem to package with serverless and work with amazon lambda for some reason? I’m not sure why.

I want to confirm if anyone else is able to get sequelize library to actually work with serverless on one of their endpoints?

This is the library I’m trying to get working (http://docs.sequelizejs.com/), very popular ORM for nodejs.

You might need to compile the binaries for mysql2 in the linux container of the lambda environment

If you install them on your local machine they are compiled for mac/windows etc and not the AWS lambda linux distro

This post discusses how to compile native binaries for usage in lambda https://claudiajs.com/tutorials/pandoc-lambda.html

i see that this post was written a month ago and i’m interested if you have found answers to your questions and generally if you have any updates?

According to Joe’s SO post, the problem was resolved by forcing Serverless to include the mysql library in its bundle. I believe this issue occurs because webpack does not realize that mysql is a dependency until runtime.

I had a similar problem with Sequelize + Postgres, except my missing library was “pg”. I resolved it in the same way as Joe did. Check out his post: https://stackoverflow.com/questions/48554917/getting-sequelize-js-library-to-work-on-amazon-lambda

1 Like

We’ve been using Serverless with Sequelize 3 for years in Lambda. It works fine. There’s a connection pool issue in Sequelize 4 that was just fixed recently to make it work for Lambda as well. I don’t know if it’s integrated yet.

We’re not using Webpack on the back end (just our front end) so maybe that’s why we never had an issue with the MySQL 2 library. We certainly didn’t have to recompile anything and most of our developers are on Windows.