---
# System prepended metadata

title: '[Tide Protocol](https://www.tideprotocol.xyz) :: AWS Pipeline'

---

# [Tide Protocol](https://www.tideprotocol.xyz) :: AWS Pipeline

## Summary

In this document we describe an overview of the services used for our setup, and the way in which they are interconnected.

1. **EC2 Autoscaling**: Instances are setup with the `tide-backend-auto-scaling-group-staging` group composed of *t2.medium* instances, configured with the following capacities: 1 (minimum), 2 (ideal), 4 (maximum). The group is also setup with *Blue/Green* revision with *AllAtOnce* policy. This means that if we are to trigger an update to the group, new instances are spawned in parallel and 1 hour after a successful traffic transition the old ones are terminated. Otherwise the update will fail.

3. **Api Gateway**, Virtual Private Cloud (VPC) using all 3 /16 subnets available for `eu-west-1`.

4. **VPC**: One custom VPC endpoint (VPCE), `s3-to-ec2-vpc-access-link` used to give internal access to our private S3 bucket.

5. **S3**: Private bucket for storing environment variable accessible only by *VPCE*: `tide-protocol-env-variables`

6. **AMI** - Image of the instance to initialize EC2s in autoscaling group. Basic amazon linux instances with only nvm, pm2, codedeploy installed.

7. **CodeDeploy (aws)** setup the deployment of the EC2 Autoscaling group. The AMI template already has CodeDeploy installed, so we only specify the building and running steps on the `appspec.yml` file on our repository. 

8. **CodeDeploy (github)** Pipeline to upload the repository to our AMI template and provision an EC2 Autoscaling group update with the new deployment.

---

## Additional Thoughts

- All scripts that need to be run before or after the deployment of the new code versions can be called from the `appspec.yml` file under the 'hooks' section.

- We will have 2 apps, one for staging and one for production. We want to bind them together with CodePipeline with an approval step in between before the prod deployment.

- We don't deal with environment variables the usual way: instead, we have a storage bucket just for the env vars. Ideally we will have a quick way to update the contents of that bucket, but for now we do it either via AWS CLI or AWS web UI.


## Still to figure out

- How do we setup automatic triggers for deploy on specific branches?

- How do we handle CI pipeline runs before deploy?



