This code helps deploying the sample CRUD rails app to AWS lambda using Serverless framework.
Before you continue, please clone this repository to your local machine.
# Change directory to your preferred location
cd <local dev path>
# Clone the repo
git clone https://github.com/vedsingh-fullstack/serverless-rails.git
# Alternatively, with SSH,
git clone [email protected]:vedsingh-fullstack/serverless-rails.git
Install the serverless CLI via NPM
npm install -g serverless
As lambda is using the ubuntu image, gem installation with native extension will not work. We have used the lambci docker image(https://hub.docker.com/r/lambci/lambda/) to install the package with native extension to test serverless function locally.
docker run -v `pwd`:`pwd` -w `pwd` -it lambci/lambda:build-ruby2.7 bundle install --no-deployment
docker run -v `pwd`:`pwd` -w `pwd` -it lambci/lambda:build-ruby2.7 bundle install --deployment
To test the function mentioned in serverless.yml file locally in lambda like enviroment use the following
docker run --rm -v "$PWD":/var/task:ro,delegated -e RAILS_ENV=staging lambci/lambda:ruby2.7 app/composites/user/handler/listUser.Handler.process
# Run with event
docker run --rm -v "$PWD":/var/task:ro,delegated -e RAILS_ENV=staging lambci/lambda:ruby2.7 app/composites/user/handler/update_user.Handler.process '{"event": "test_event"}'
We can also test already deployed function locally using serverless cli
sls invoke -f listUser
We can deploy all the function at once to serverlss using sls deploy
,
sls deploy --aws-profile personal_aws
We can also deploy individual function which is quicker,
sls deploy function --function listUser --aws-profile personal_aws