DEV Community

Cover image for Simple MEAN-Stack deployment by AWS CloudFormation & Docker 🐳
Thomas Gotwig
Thomas Gotwig

Posted on • Edited on

Simple MEAN-Stack deployment by AWS CloudFormation & Docker 🐳

Deploying AWS apps mainly over the AWS homepage takes much time, we can reduce this time a lot by using code-as-infrastructure principles by using the great AWS-CLI and AWS CloudFormation! 🚀

This guide is mainly for beginners which wants a quick & simple overview 🙂 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/simple/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

From that, surf towards http://3.70.190.17 to see it 👀

Hosted app

You can remove the entire stack by running make rm! 🔥

I really hope you enjoyed this story and wish you happy coding! 🤗🖥

Top comments (4)

Collapse
 
tomowatt profile image
Tom Watt

Nice read, though I am curious to the possible reasoning for not using ECS or an ECS Optimised AMI?

Collapse
 
tgotwig profile image
Thomas Gotwig

Hello and thanks tomowatt 🙋‍♂️🦖

I think I didn't know ECS when I wrote this (almost 1 year ago), what are the advantages of ECS? 🙂
Perhaps I will take a look once my AWS account is reactivated 🤠

Collapse
 
tomowatt profile image
Tom Watt

Ah okay, that explains - there are too many services on AWS to be honest!
Main advantages of ECS would be the deployment, management and monitoring of Containers, even if they are deployed on EC2 instances.
Though setting up ECS Tasks with CloudFormation is a bit long winded - looking into doing this for a new work project.
With that, using the ECS Optimised AMIs means you don't have to install Docker as it's preinstalled.
Would recommend checking out ecs-cli compose as you can deploy straight from the Compose File to AWS - which is pretty awesome!

Thread Thread
 
tgotwig profile image
Thomas Gotwig

Yeahh~ way too many 🙈
Oh cool thank you! 🤩 I think I will take a closer look 🕵️‍♂️