DEV Community

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

Posted on • Updated 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 πŸ•΅οΈβ€β™‚οΈ

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.