AWS Static Website Deploy
This setup up the resources needed to deploy a static website to S3.
How it works.
GitHub notifies the ApiGateway that a push was received
ApiGateway triggers a lambda function to start a CodeBuild build
CodeBuild fetches the code and builds the site. It uploads the artifact (the built site) to s3.
S3 triggers lambda to deflate the archive and puts the files into the root of the bucket to be served by S3
GitHub -> ApiGateway -> Lambda -> CodeBuild -> S3 -> Lambda -> S3 -> WWW
Run the template
Use the AWS CloudFormation template to create the stack.
Setting up the build trigger
We can't create the S3
NotificationConfiguration in the first run of the template because it creates a circular dependency
bin/connect-s3-lambda script will handle setting up this relationships for you after the template runs. The
NotificationHookupCommand can be used as a copy/run command for getting this setup.
If you don't want to use the
default profile for the aws-cli to authenticate another profile name can be passed using the
Configure your project for CodeBuild
There are a few assumptions made by the build system.
The code to deploy to s3 will be built into
The build will create a
build-output.zipfile in the root of the project.
This example file will install
yarn and install modules then run the
version: 0.1 phases: install: commands: - curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - - echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list - sudo apt-get update - sudo apt-get install -y yarn - sudo apt-get install -y zip pre_build: commands: - yarn install build: commands: - yarn run build post_build: commands: # Zip the public folder. - zip -r build-output.zip public artifacts: files: - build-output.zip discard-paths: yes
Enable the WebHook
Head to your GitHub repo.
Settings -> Webhooks -> Add webhook
The default config is fine.
Payload URL paste in the value from
HookURL in the template outputs.