This page will provide you with the instructions on how to install and use Wrapper.js.
Table of Contents
Setup
To help visualise exactly what you’re doing, I’ll illustrate each step of the set up process.
Open a terminal window and run aws configure
to set your AWS credentials locally.
Have a look at the summary page and decide on a template you want to use.
In the terminal window and use the cd
command to ensure you’re in a folder location you want the template to be copied to.
Run the unwrap
command and select your chosen template.
The CLI will first ask if you are happy for Wrapper.js to create an AWS secret for you and if so will prompt you to enter details for the templates configuration.
If you don’t want Wrapper.js to create a secret for you, select no and create the secret manually yourself based on the instructions in your selected template’s page.
Then the CLI will ask if you are happy for Wrapper.js to create an S3 bucket to store the Terraform state file and so then it will do this for you as part of the set up process.
If you don’t want Wrapper.js to create the S3 bucket for you, select no and create the S3 Bucket manually yourself – make sure to match the same S3 bucket name used in the AWS Secret configuration.
Once completed:
- your template will be created in your local directory
- and (if you allowed Wrapper.js to do so) your AWS Secret and S3 Bucket will be created for you
Be sure to remember the name of the secret you’ve just created for the next step!
Use the name of the secret you’ve just created (lets pretend you called it ‘example’, be sure to replace this with your actual secret name) and run: gobble secrets example
This will create an environment variables JSON file that will configure your Terraform set up for the next step.
Run the following command to initiate your local Terraform set up with the environment variables you’ve just created: gobble tf init
Then run gobble tf plan
to show you what Terraform plans to do, if you’re happy then run gobble tf apply
These commands mimic the original Terraform commands, except they pass the retrieved secrets into Terraform as environment variables – see the gobble tf commands here.
Once these new Terraform resources are created, you can then move onto the next step!
If at any point you want to destroy these resources, the command is gobble tf destroy
Now you’ve created your AWS resources with Terraform, we need to retrieve information from these resources to create ENV files for both the Front End and Back End.
To do this, re-run the secrets command, using the name of the secret you created (e.g if the name of the secret you created was called example, then you’d run gobble secrets example
– be sure to replace example with your actual secret’s name).
At the point you can skip to local host development – if however you’d like to deploy your Back End logic you can run the command gobble sls deploy
from the root directory.
These commands mimic the original Serverless Framework commands, except they pass the generated environment variables generated in step 6 – see the gobble sls CLI commands here.
The Back End is deployed to the API Gateway that was created by Terraform.
To remove these resources, run the command gobble sls remove
As with the previous step, you can skip this if you want to crack on with localhost development – otherwise if you’d like to deploy your Front End app then run the command gobble next export
This command mimics the Next.js command that exports a static build of React.js app, then it deploys the build to an S3 bucket, see code for reference.
You can then visit the app on the domain name that you used in your secrets file.
You can remove the Front End by running the command that destroys all Terraform resources: gobble tf destroy
Develop
Now you’ve set up your Terraform cloud resources and generated your ENV files, you can now run gobble dev
to run your configuration locally.