Setting things up

Since serverless framework is being used, you need to install the npm package for serverless.

npm install serverless -g

Create a directory named bookshelf and run the following command

cd bookshelf

serverless create --template aws-ruby

This will create a serverless.yml file and a handler.rb file.

Lets organize http handlers in a handlers directory; models in the models directory. Create these folders and move the handler.rb file to the handlers directory, renaming it to test.rb.

mkdir models handlers
mv handler.rb handlers/test.rb

Getting AWS credentials

Login to AWS console, and from IAM service create a new user. For example, name the user - sls-user01. Enable programatic access. In the permissions page, select Attach existing policies directly and click on Create policy. Select the JSON tab, add the following JSON file you’ll find in this gist.

Copy the Access Key ID and Secret access key from the final step of user creation.

Now export the AWS credentials to be used for deployment.

export AWS_ACCESS_KEY_ID=<your-key-here>

export AWS_SECRET_ACCESS_KEY=<your-secret-key-here>

Open the serverless.yml file created and add an http endpoint, to the handler, by changing the functions section(note the intendation).

# File: serverless.yml

    handler: handlers/test.hello
      - http:
          path: hello
          method: get

Deploy time. Run serverless deploy from the bookshelf directory.

This will display a set of messages and finally show the service information, that got deployed successfully. From the service information, copy the endpoint and send a GET request to it from a http client like Postman. You should get a successful message.

Get notified on engineering articles like this

Follow us on twitter @neumeralhq