This project is built, tested and deployed to AWS by CodeBuild. There are two components to deploy - the Serverless service and all supporting infrastructure which is defined with Terraform (CodeBuild, Route53, CloudFront etc.).
I've created Docker-powered build/deployment environments for Serverless projects and Node projects to use with AWS CodeBuild and Bitbucket Pipelines.
To deploy/manage the Serverless service you will need to create an IAM user with the required permissions and set credentials for this user - see here for further info. After you have done this, run the commands below to deploy the service:
TODO
E.g. yarn run deploy
yarn install
yarn run deploy
All commands below must be run in the /infrastructure directory.
To deploy to AWS, you must:
- Install Terraform and make sure it is in your PATH.
- Set your AWS credentials using one of the following options:
- Set your credentials as the environment variables
AWS_ACCESS_KEY_ID
andAWS_SECRET_ACCESS_KEY
. - Run
aws configure
and fill in the details it asks for. - Run on an EC2 instance with an IAM Role.
- Run via CodeBuild or ECS Task with an IAM Role (see buildspec-test.yml for workaround)
- Set your credentials as the environment variables
- Update and export all environment variables specified in the appropriate buildspec declaration (check all phases) and bash scripts
- Initialise Terraform:
terraform init \
-backend-config 'bucket=YOUR_S3_BUCKET' \
-backend-config 'key=YOUR_S3_KEY' \
-backend-config 'region=YOUR_REGION' \
-get=true \
-upgrade=true
terraform plan -out main.tfplan
terraform apply main.tfplan
- Update and export all environment variables specified in the appropriate buildspec declaration (check all phases) and bash scripts
- Make necessary infrastructure code changes.
- Initialise Terraform:
terraform init \
-backend-config 'bucket=YOUR_S3_BUCKET' \
-backend-config 'key=YOUR_S3_KEY' \
-backend-config 'region=YOUR_REGION' \
-get=true \
-upgrade=true
terraform plan -out main.tfplan
terraform apply main.tfplan
- Update and export all environment variables specified in the appropriate buildspec declaration (check all phases) and bash scripts
- Initialise Terraform:
terraform init \
-backend-config 'bucket=YOUR_S3_BUCKET' \
-backend-config 'key=YOUR_S3_KEY' \
-backend-config 'region=YOUR_REGION' \
-get=true \
-upgrade=true
terraform destroy