# Deploy Ghost on AWS using CloudFormation - Part 04

🚨 Check out the [latest source code](https://github.com/jayanath/ghost-blog-in-aws) if you are following along. I wouldn't trust the screenshots that much as they are bit outdated with latest updates to the code 😅🙏🏻

In the part 03 of this series we got the basic infrastructure ready. Now we can continue to build our Ghost host server on that. Before anything, its best to setup `AWS-CLI` to use `Systems Manager (SSM)` so that we can connect to the Ghost host without leaving the terminal. Following the [AWS documentation](https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html) gets us setup in few minutes. 

![ssm-session.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1650714380589/fEOuwFoPf.png)

Also we need to have a real domain name for test secure site setup etc. I always use jayforweb.com as my test domain and I use google domains as my domain registrar.

Now we have to setup the followings in our Ghost host.

- Docker
- Docker-compose
- Traefik container
- Ghost container
- Route53 hosted zone
- Route53 record set

CloudFormation made this easy by providing us some helper scripts. We use `cfn-init:file` to create configuration files and copy they to the appropriate places. Also we use `cfn-init:commands` to install and setup `Docker` and `Docker-compose`. Also we need to add Route53 hosted zone and the record set with our domain name.

[The `ghost-host-setup.cfn` template](https://gist.github.com/jayanath/6db76af72832f2f93e6cfbf3cd76812b) contains all these changes. Have a quick look 👀 if needed.

We need to add an alias record as `www.jayforweb.com` to point to `jayforweb.com`. I tried to create a record set for that but didn't work. So we will revisit that later.Now its time run our CloudFormation to see what it creates! [yeah, just delete the old stack to start fresh]

`make create-blog-host-stack STACK_NAME=ghost-host-1`

It's always handy to know where to look for any errors. On our Ghost host, we can find all the logs under `/var/log`

|![ghost-logs.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1650715378313/x3pdCcoZa.png)|
|:--:|
|*Log files under /var/log on Ghost host*|

`cfn-init-cmd.log` file is what we should look first. After the deployment our log shows happy faces.

|![ghost-logs-2.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1650715491242/iJJvJcD8a.png)|
|:--:|
|*Check all the commands for any errors*|

Now we can verify whether our configuration files are in place at `/data/traefik`. Obviously they should be as we had no errors at all.

![ghost-logs-3.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1650715591069/8O8OQP_xS.png)

The site is up, with one small problem 😬. We have to tweak the `acme.json` file to get the `LetsEncryption` working properly. I remember got it working after few tries last time with my site, `fewmorewords.com` but I don't remember how I did it 🙃. I will update this post when I work it out.  But this is awesome as we got everything as code, no click-ops at all.

|![ghost-live-again.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1650715839870/akhXlRR64.png)|
|:--:|
|*YEY!! we got it working!*|

We can start up, shut down the site very easily with `docker-compose` via `SSM`. We have to make sure to use `sudo`. Also we should run `docker-compose` in `detached mode [-d flag]` when we start up the stack. Have a look at the commands in the below screenshot.

![docker-compose-up.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1650715962803/QbH6l2gsx.png)

Thats it for now and hanks for staying with me so far. As always the [full code is on github](https://github.com/jayanath/ghost-blog-in-aws) if you want to try this out by yourself.

Cheers 🍻 until next time! 




