coding and cooking

Creating and configuring AWS Elasticsearch using v4 signature in a Rails application

It's easy to setup a Rails app to access an AWS Elasticsearch instance through version 4 signature. This are the versions of the resources used:

  • Ruby version 2.1.8
  • Rails version 3.2.22
  • gem elasticsearch-transport-aws4 version 2.0.0
  • gem faraday_middleware-aws-signers-v4 version 0.1.6

Creating the AWS Elasticsearch instance

It's very easy to create and configurate your AWS Elasticsearch instance. Just follow the steps below.

Enter your AWS Console and search for Elasticsearch

Following the image sequence below, search for Elasticsearch service on AWS:

  • Click in Services (the first menu button)

  • Enter 'elasticsearch' on the input and choose the 'Elasticsearch Service'

  • On Elasticsearch Service dashboard, click the button Create a new domain

Choose the instance configuration. Any doubts, just click in the question mark on right top - same line of the title, 'Configure cluster'.

  • Define the policy

Click in Modify access policy when changing or...

Read more

Awesome RESTful API with Rails

Awesome RESTful API with Rails

If you are coding in Ruby with Rails, at some moment inexorably you will need to build a RESTful API, to respond some external HTTP requests. So, let's consider to create a JSON API and let's do this with elegance and the right way, i.e., testing!

For this post, I'm using:

So, basically, our task will be to send HTTP requests and test the response status code for each one and it's body contents; it needs to match our expectations.

The app I created for this post is in a repository on Github. It's a products managing example app.

What we want to test?

As said previously, we will focus in two things: the response body and status code of it. I think this is the most important stuff of a good API application test. Testing the body we testify if our application is sending the right content, if it's possible. What you mean with...

Read more