Skip to content

markhobson/craftcms-aws

Repository files navigation

Craft CMS on AWS

This project shows how to run Craft CMS on Amazon Web Services. It is deployed as Docker images to Amazon ECS using CircleCI for continuous integration. The build pipeline uses npm to generate the site's CSS from customisable Bootstrap SCSS.

Getting started

Follow these steps to create a Craft CMS site on AWS.

1. Create your project

Start by creating your own project:

  1. Fork this project to your own GitHub account
  2. Clone your repository locally

2. Configure AWS

We'll use Amazon Web Services to host your site.

  1. Create an Amazon Web Services account if you haven't already got one
  2. Create admin user
  3. Create a key pair admin-key-pair-london
  4. Create ci user
  5. Create ci group with policies:
    • AmazonEC2ContainerRegistryPowerUser
    • AmazonEC2ContainerServiceFullAccess (?)
  6. Decide on an AWS region, e.g. eu-west-2

3. Configure CircleCI

We'll use CircleCI for continuous integration.

  1. Sign up to CircleCI with your GitHub account if you haven't already done so
  2. Add your forked project
  3. Add the following environment variables to the project with your ci user credentials and chosen region:
    • AWS_ACCOUNT_ID
    • AWS_ACCESS_KEY_ID
    • AWS_SECRET_ACCESS_KEY
    • AWS_DEFAULT_REGION

4. Install AWS CLI

We'll use the Amazon CLI tools to bring up the necessary infrastructure.

  1. Install AWS CLI
  2. Configure AWS CLI using your admin user credentials and chosen region
  3. Install Amazon ECS CLI
  4. Configure Amazon ECS CLI using your admin user credentials and chosen region:
ecs-cli configure profile --profile-name default --access-key ${AWS_ACCESS_KEY_ID} --secret-key ${AWS_SECRET_ACCESS_KEY}
ecs-cli configure --cluster craftcms-aws --region ${AWS_DEFAULT_REGION} --config-name default

5. Create AWS infrastructure

To create your Amazon ECR and ECS services:

./bin/aws-up.sh

Note that you'll be charged for these services until they are destroyed.

6. Deploy site

Push a change and CircleCI will deploy the site to AWS. Once the job is complete find the site's IP address using:

ecs-cli ps

Visit http://<ip-address>/admin to run the Craft CMS installer. Once complete, visit http://<ip-address> to view your site.

Running locally

You can run the site locally as follows:

  1. npm install
  2. npm run dist
  3. docker-compose up --build
  4. Visit http://localhost/admin

To watch SCSS:

npm run watch

Destroy AWS infrastructure

To destroy the services:

./bin/aws-down.sh

Using CloudFormation (Experimental)

There's work-in-progress to use AWS CloudFormation rather than the AWS CLI to provision the infrastructure. The CloudFormation template template.yml currently deploys a vanilla CraftCMS instance to AWS ECS using RDS for the database.

To create the stack:

aws cloudformation create-stack --stack-name craftcms-aws --template-body file://template.yml --capabilities CAPABILITY_IAM

To destroy the stack:

aws cloudformation delete-stack --stack-name craftcms-aws

TODO

  • Upgrade to Craft 3
  • Style news templates
  • Automate CircleCI primary image build in DockerHub
  • Ensure database is private
  • Prod/dev environments
  • Fargate
  • CloudFormation (in progress)
  • RDS (in progress)
  • DNS
  • SSL
  • Local deployment (i.e. execute .circleci/config.yml locally)