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.
Follow these steps to create a Craft CMS site on AWS.
Start by creating your own project:
- Fork this project to your own GitHub account
- Clone your repository locally
We'll use Amazon Web Services to host your site.
- Create an Amazon Web Services account if you haven't already got one
- Create
admin
user - Create a key pair
admin-key-pair-london
- Create
ci
user - Create
ci
group with policies:AmazonEC2ContainerRegistryPowerUser
AmazonEC2ContainerServiceFullAccess
(?)
- Decide on an AWS region, e.g.
eu-west-2
We'll use CircleCI for continuous integration.
- Sign up to CircleCI with your GitHub account if you haven't already done so
- Add your forked project
- 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
We'll use the Amazon CLI tools to bring up the necessary infrastructure.
- Install AWS CLI
- Configure AWS CLI using your
admin
user credentials and chosen region - Install Amazon ECS CLI
- 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
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.
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.
You can run the site locally as follows:
npm install
npm run dist
docker-compose up --build
- Visit http://localhost/admin
To watch SCSS:
npm run watch
To destroy the services:
./bin/aws-down.sh
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
- 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)