Devops engineers tend to use languages like bash and python to automate processes, which can look a bit alien to a ‘JS person’.
I recently created Wrapper.js and want to explain how it uses NextJS, Terraform and Serverless Framework to automate devops processes.
In this post, I will explain how Wrapper.js uses these core technologies together and why they are a great combination!
Table of Contents
What is NextJS, Serverless Framework and Terraform?
NextJS is an opinionated front end framework, that helps developers build ReactJS applications.
It comes bundled with a load of super useful features that helps speed up development, such as: code bundling, code splitting, minification, uglification, page based and Application Programming Interface (API) routing etc.
I’ll be writing a post soon explaining further details on what NextJS is and why it is great.
How do users interact with NextJS, Serverless Framework & Terraform?
So you now understand what these technologies are, but practically speaking – how do users engage with these frameworks?
I’ve sketched a diagram that takes you through the journey of what these technologies do from a users perspective, when they interact with your website:
So talking through this process:
Starting at the top left of the diagram, a person uses their computer to open a web browser and visits your website.
How can developers leverage NextJS, Serverless Framework & Terraform?
Having spoken through how these technologies are perceived from a users perspective, lets go through how these technologies can be used practically speaking by the developer.
I’ve put together a diagram below, that talks through how a developer can leverage NextJS, Terraform & Serverless Framework – through the use of a NodeJS wrapper script.
Talking through how this process works from the developers perspective:
- A developer sets up an AWS account.
- In the AWS account they create IAM credentials, a list of secrets in Secrets Manager (for the NodeJS wrapper script) and two S3 buckets (one for Terraform state and the other for Serverless Framework state).
- On the developers local machine: they set up their AWS IAM access credentials, a NodeJS wrapper script, Terraform, Serverless Framework and NextJS.
- The developer runs npm commands via the NodeJS wrapper script, to deploy Terraform and Serverless Framework resources, then deploys a NextJS app to newly ‘Terraform generated’ S3 bucket.
Why these technologies are so great when they work together!
There was a lot said in that last section, especially in step four – I want to go a little further into that to help show what is actually going on and why these technologies work so well together.
Once the developer does the manual set up of the initial AWS resources (labelled in blue) and sets up AWS access on their laptop, they are then ready to run the NodeJS wrapper script – this is where the magic happens.
Wrapping up (get it? 😉)
Hopefully at this point you can see why these technologies work well together, to summarise:
In my opinion, the real power of these technologies becomes apparent once they are integrated into a continous deployment pipeline that uses a wrapper script to automate the process of generating and managing environments.
I’ve created a diagram that fully shows you this potential:
Explaining this diagram:
- A developer pushes their code to a Bitbucket repository.
- The repository has AWS access credentials stored on its pipeline and feeds commands to the NodeJS wrapper script depending on which branch was pushed to.
- In a scenario where a developer pushed new code to the ‘dev’ branch, then the wrapper script would execute a command that retrieves secrets relating to the ‘dev’ environment, then uses NextJS, Serverless Framework and Terraform to fully deploy / manage the ‘dev’ environment. The same process would happen for ‘stage’ or ‘prod’ environments.
This has been another pretty heavy devops post, but I hope it has been helpful in understanding why a NodeJS Wrapper Script for NextJS, Terraform and Serverless Framework is so good 😀