The last decade has seen almost all organisations, migrate or develop application to cloud infrastructure. The application architecture related to platform and hosting evolved from hybrid, multi-cloud and serverless. The main driver behind adoption of serverless architecture was auto-scaling capability at optimized cost with minimal maintenance and no charge when idle. The highlight is “build more and manage less” and multi-language support.
In this post and subsequent ones, I have attempted to provide information to solve the issues I had stumbled upon and solution derived from different links in the web. For now I am focussing on NodeJS as the programming language. Serverless architecture here is realised by writing a serverless configuration file, serverless.yml and installing the serverless node module. A little knowledge of deployment templates, like cloud formation is good to know, to start using serverless. In fact, in depth knowledge of cloud formation will help when we need to attempt something new not available in serverless documentation. At the moment of writing the post, I found the documentation is good, but require more to complete many more use cases. Here it becomes a trial and error in trying different options and making it work. I have has the opportunity to try serverless on AWS, so all the information here is related to the single environment, AWS. I am planning to break this up in sections as:
- Setting up serverless in a nodejs environment
- The basic building blocks of serverless configuration file
- A serverless configuration for api gateway, lambda and sqs (the current post)
- Provide observability and operational analytics using cloudwatch logs and alarms, and configuration of the same
- Securing credentials using encoding and decoding secrets
- drive continuous integration and deployment for serverless using github actions
- Use Serverless offline for development in local environment
Setting up serverless in a nodejs environment – This involves the following steps:
- Install NodeJs, most likely versions beyond 6.
- Install the dependencies for serverless
- Setup the serverless CLI
Setup of a serverless CLI involves installing serverless as self executable mobile locally in our development machine.
npm install -g serverless
The above command installs serverless globally, I normally resort to invoking serverless executable found within the node_modules folder. This will be available after an npm install
command is run. serverless.js is same as sls
command that you will find on web. Going this way allows me to maintain the local version of serverless for each project I am working on. Different projects run on different nodejs and serverless versions.
$ ./node_modules/serverless/bin/serverless.js
Serverless documentation also talk about connecting to dashboard server, that is useful for managing multiple applications across single AWS account, but I have skipped serverless dashboard SaaS application during my development. It is useful nevertheless. This will invoke a CLI interactive session, asking us to choose dashboard, and it will initialize a serverless project for us. (https://www.serverless.com/framework/docs/getting-started).
We can now look into serverless configuration file in the next blog.