A Serverless Framework project configured to be used with a Postgres db and Sequelize ORM
This repository is the result of some work to get an AWS Lambda working with relational database. It can be used as a starter for others that want to connect their serverless function to a new or existing relational database.
- uses Serverless Framework to upload an AWS Lambda Layer containing Postgresql binaries, so your Lambda function can talk to an AWS RDS instance running Postgres
- pre-packaged Postgres Binary, so all you need to do is run
sls deploy -s prod
and the layer will be uploaded with your function - Sequelize db connection to AWS RDS instance;
- Sequelize migrations to AWS RDS instance;
- pre-configured
dev
andprod
environment through theserverless.yml
- clone or fork this project
- have Serverless Framework already configured and connected to your AWS account with
sls config credentials
(read more here) - add a
config.json
to theconfig
folder to enable use ofsequelize-cli
to run your migrations locally and push them to production server (see here for more info on how to format this file) - on local,
npm install
, then (if serverless is already installed)serverless plugin install —name serverless-offline
andserverless plugin install —name serverless-sequelize-migrations
if you intend to use sequelize to run migrations from this codebase to your local and production databases. - most configuration is located in the
serverless.yml
. You will need to change the following configuration to be consistent with your own AWS RDS instance:vpc > securityGroupIds
,vpc > subnetIds
prod
database credentialsdev
database credentials
- if you want to run any migrations use
sls migrations up
If you have any problems please create an issue and I'll try to address it.