Donut

Automating NextJS, SLS and Terraform with Wrapper.js

Combine NextJS, Serverless Framework & Terraform using Wrapper.js

If you’re a JavaScript developer, Devops can at times be a bit of a chore to set up.

Devops engineers tend to use languages like bash and python to automate processes, which can look a bit alien to a ‘JS person’.

Wouldn’t it be great if we could just automate everything using JavaScript?!

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?

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:

Diagram showing how NextJS, Serverless Framework and Terraform are seen by a user when your site is visited.

 

Diagram showing how NextJS, Serverless Framework and Terraform are seen by a user when your site is visited.

So talking through this process:

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.Diagram showing the stack of technologies that can be used by a developer to orchestrate NextJS, Terraform and Serverless Framework.

Diagram showing the stack of technologies that can be used by a developer to orchestrate NextJS, Serverless Framework and Terraform.

Talking through how this process works from the developers perspective:

  1. A developer sets up an AWS account.
  2. 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).
  3. On the developers local machine: they set up their AWS IAM access credentials, a NodeJS wrapper script, Terraform, Serverless Framework and NextJS.
  4. 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.

Diagram showing how the developer utilises NextJS, Terraform and Serverless Framework via a NodeJS wrapper script.

Diagram showing how the developer utilises NextJS, Serverless Framework and Terraform via a NodeJS wrapper script.

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:

Diagram of how a NodeJS wrapper script is used within a CD pipeline to manage multiple environments.

 

Diagram of how a NodeJS wrapper script is used within a CD pipeline to manage multiple environments.

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 😀

 

Share this post