DEV Community

Cover image for Load-Balanced MEAN-Stack by AWS CloudFormation & Docker 🐳
Thomas Gotwig
Thomas Gotwig

Posted on

Load-Balanced MEAN-Stack by AWS CloudFormation & Docker 🐳

In this short article I will show how to deploy a Mean-Stack app by AWS-CLI and CloudFormation using a v1 load-balancer πŸ˜ƒ

All the code regarding our deployment you can also find here:
https://github.com/TGotwig/devops

We take usage of an very nice and simple MEAN-Stack project which comes from Brad Traversy πŸ€—

Download the sample repo and cd into it:

git clone git@github.com:TGotwig/devops.git
cd aws-cloudformation/solutions/advanced/mean-stack
Enter fullscreen mode Exit fullscreen mode

βš™οΈ Setup awscli

Install the awscli from somewhere and login:

aws configure --profile <YOUR_AWS_ACCOUNT_NAME>
Enter fullscreen mode Exit fullscreen mode

You will be asked for two IDs, you can get them through:

Click on your name at the top right corner and then on  raw `My Security Credentials` endraw

Open the tab  raw `Access keys (access key ID and secret access key)` endraw

Let it create two keys for you for later use

βš™οΈ Setup ssh

Create a file called parameters.json:

[
  {
    "ParameterKey": "KeyName",
    "ParameterValue": "<KeyName>"
  }
]
Enter fullscreen mode Exit fullscreen mode

Replace <KeyName> by your SSH key under EC2 / Key Pairs:

Screenshot_2020-10-10 Key pairs EC2 Management Console(1)

βš™οΈ Setup Makefile

Create a file called .env for the Makefile:

stack-name=simple-mean-stack
profile=<YOUR_AWS_ACCOUNT_NAME>
region=<YOUR_AWS_REGION>
Enter fullscreen mode Exit fullscreen mode

πŸš€ Run it!

Start it by running make up, an EC2 machine should boot up:

Created EC2 machine with public IPv4 address

After some time we can reach the app, run make getUrl to get the url:

App with ID from machine x

After refreshing the page few times you should see another IP:

App with ID from machine y

You can remove the entire stack by running make rm! πŸ”₯

Awesome! Now we have finished our load-balanced Mean-Stack app πŸ˜ŽπŸŽ‰

Top comments (0)