AWS S3 Static Site with Ansible
Deploys an AWS S3 bucket as a static web site (HTTP) using Ansible.
Quick Start
-
Clone this repository:
git clone https://github.com/1homas/AWS_S3_Static_Site_with_Ansible.git
-
Customize any settings in the
vars.yaml
file:project_name
: use a project name to tag AWS resources for tracking and easy termination when done
⚠ The bucket name is based on the
project_name
by default and must be globally unique for all of AWS. If you get a403
error when running the playbook, you need to modify theaws.s3.bucket_name
invars.yaml
to be more unique. -
Create your Python environment and install Ansible:
pip install --upgrade pip pip install pipenv pipenv install --python 3.9 pipenv install ansible boto boto3 botocore pipenv shell
If you have any problems installing Python or Ansible, see Installing Ansible.
-
Export your AWS Access & Secret keys into your terminal environment:
export AWS_REGION='us-west-1' export AWS_ACCESS_KEY='AKIAIOSF/EXAMPLE+KEY' export AWS_SECRET_KEY='wJalrXUtnFEMI/K7MDENG/bPxRfi/EXAMPLE+KEY'
or you may source these variables from a file:
source ~/.env/aws.sh
-
Run the Ansible playbook:
ansible-playbook playbook.yaml
-
Try your new static site at
http://{{ aws.s3.bucket_name }}.s3-website-{{ aws.region }}.amazonaws.com
! -
When you're done, you may terminate the instances and remove all resources :
ansible-playbook terminate.yaml
Playbooks
playbook.yaml
: the main playbook to create the S3 bucket and static siteterminate.yaml
: delete the S3 bucket and all objects within itaws.s3.list.yaml
: list the AWS S3 bucket keys (files and directories)aws.s3.sync.yaml
: [re]sync the contents of the localfiles
directory to the AWS S3 bucketaws.show.yaml
: show all AWS resources for the current AWS IAM user
License
This repository is licensed under the MIT License.