Deploy Ghost on AWS using CloudFormation - Part 04

Deploy Ghost on AWS using CloudFormation - Part 04

NOTE: The full source code can be found at The screenshots may be bit outdated.

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 gets us setup in few minutes.

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

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

  1. Docker
  2. Docker-compose
  3. Traefik container
  4. Ghost container
  5. Route53 hosted zone
  6. 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, Docker-compose. Below is the new expanded version of our Ghost host resource.

We need to add Route53 hosted zone and the record set with our domain name.

    Type: "AWS::Route53::HostedZone"
        Comment: 'Hosted zone for test domain'
      Name: ''

    DependsOn: MyGhostHostedZone
    Type: AWS::Route53::RecordSet
      HostedZoneId : !Ref MyGhostHostedZone
      - !GetAtt MyGhostHostInstance.PublicIp
      TTL: '300'
      Type: A
Route53 hosted zone and the record set

We need to add an alias record as to point to 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! I deleted my stack to start fresh. Just imagine if we had to delete the resources manually, one by one :-) This is why I love CloudFormation.

make create-blog-host-stack STACK_NAME=ghost-host-1
Execute the target from make file

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

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.

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.

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 this site, but I dont 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.

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 at work

WOW! This became a very long post and thanks for staying with me so far. As always the full code is on github if you want to try this out by yourself.