Design a site like this with WordPress.com
Get started

[9] [ProjectX] – Easy Deployment using Claudia.js framework

Source code: https://git.io/fjllX

If you are like me, after reading the title, you would say, Oh No, One more framework!. I understand. But please bear with me and you will appreciate this one.

Unless you are a JavaScript developer, you are not accustomed to learning 50 different frameworks (ok.10). In fact, I reckon, in JavaScript world, it is easier to develop a new framework then to think of a name for it.

But then, the same JavaScript community has come to our rescue and provided us a framework that works like a charm in easing deployment burden of our Serverless API projects. Let’s look at one of them. Enter Claudia.js

Claudia.js framework makes deployment of Node.js to AWS very easy. This framework is only for Node.js/JavaScript based projects. For other technologies, here is a short list of frameworks currently available

Framework Technology
Claudia.js Node.js
Jets Ruby
Riff Kubernetes
Chalice / Zappa Python
Sparta Go

This is a fast-moving space and hence you will find other frameworks getting more popular at later time.

Setup Node.js project and Install Claudia.js

STEP-1:

Open your Cloud9 IDE and create a folder called ClaudiaJS under root folder

STEP -2:

Right-click on ClaudiaJS folder and Open Terminal Here

STEP -3:

Now let’s initialize Node.js project. Enter following command

npm init

Enter following details.

  • Package name: fullname
  • Description: package for fullname api

Let rest of the values be taken as defaults by pressing ENTER key

On final prompt, type yes and press ENTER

You should now see a package.json file created in the folder

STEP -4:

Now we will install Claudia.js related packages. Enter following command

npm install -g claudia

Then execute another command

npm install claudia-api-builder –s

You should see confirmation of both installations as shown below

This completes the setup. Now we will write code for what we want to do

Create Lambda function

STEP -1:

Create a new file called “index.js” under ClaudiaJS folder

STEP-2:

Write following code in index.js

That’s it. We are done. Now let’s proceed to deploy this project to create a Lambda function and API Gateway as before.

Deploy Project

STEP-1:

Go to your Terminal window and execute following command

you should see the following output confirming the deployment

Note: Make note of the Url seeing on the screen. This is the API Gateway Url that we will use for testing.

That’s it. Claudia.js has deployed the project. From our previous experience, we know it should have done the following

  • Create Lambda function
  • Create Role
  • Create API

Let’s verify if this was done

Isn’t this Super!

Remember all the grunt work we did previously to deploy Lambda and API Gateway. Thanks to frameworks like Claudia.js, it encapsulates all the complexity and boiler plate code generation and we can focus on quick deployment.

Testing

Now let’s test and see if it works as expected.

STEP-1:

Open your postman API testing tool and configure the following values

Url: https://8f4hutclwh.execute-api.us-east-1.amazonaws.com/latest/fullname

Method: POST

Request Settings: Body >> Raw >> JSON (application/json)

Body Text: {“firstName”: “Jason”,”lastName”: “Bourne”}

Your postman client should look like this

STEP-2:

Enter Send button and see the response. It should be as below

Change and Redeploy

We all know that software development is about iterations and hence, we have to keep changing and re-deploying what has already been deployed. Let’s see how Claudia.js framework helps us with that.

STEP-1:

Open index.js file and make these two changes

  • Change page name in Url from /fullname to /hello
  • Change message that we are sending back

So, your api.post function should look like below

STEP-2:

To deploy these changes, execute the following code on our terminal window

claudia update

When its finished, you should see the following screen

STEP-3:

Now go back to postman and run test again.

Note: Don’t forget to change in Url the last part (fullname to hello)

Cleanup

Since this is all a test setup, it’s time to tear it down.

Exexute the following command in your terminal window

claudia destroy

And as you would expect, it deletes everything related to this deployment. Awesome isn’t it?

Conclusion

This concludes lessons on using Claudia.js framework.

Till now we have looked at following ways to deploy Lambda & API Gateway

  • Using AWS Console
  • Using AWS CLI
  • Using AWS CloudFormation
  • Using Claudia.js framework

I am sure you would agree that option of using framework is the best out of all above. It helps in increasing your productivity and reducing repetitive work. As you keep using it more and more of it, you would not like to go back to any of above options.

Happy Clouding!

Advertisement

2 thoughts on “[9] [ProjectX] – Easy Deployment using Claudia.js framework

  1. […] we saw in earlier blog post, it is way easier to manage and deploy such projects using Claudia.js framework. So, we will be […]

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: