This repo contains server and infrastructure code for deploying and running CoEpi Cloud API on AWS.
- Compute: AWS Lambda
- Data Store: DynamoDB
- Routing and Load Balancing: API Gateway
- Permissions Management: IAM
Requirements:
- JDK11 or newer
All infrastructure concerns are managed by Terraform (v0.12+). You can either download Terraform from their site, or install it with Choco (Windows), brew (macOS), or your Linux distribution's package manager.
Terraform tracks the state of your infrastructure in a tfstate
file, which can be stored either locally or remotely. While we recommend remote state, both options are documented here for convenience.
First, create an S3 bucket to store your Terraform remote state. This will need to be uniquely named, and should be private and encrypted. A script has been provided to do this for you:
TFSTATE_BUCKET=your_bucket_name_here ./scripts/terraform_setup.sh
(If you're not sure what to name your bucket, try something like <your github username>-tcn-infra
.)
With your bucket created, go to ./terraform
in the project root directory. Copy backend.local.example
to backend.local
. Edit the contents to update the bucket
property to match the bucket name you created above. E.g.,
bucket = "s3-bucket-with-your-terraform-state"
(The backend.local
file is specific to your development environment and is ignored by source control using .gitignore
.)
Finally, initialize your Terraform project:
terraform init -backend-config=backend.local
In a terminal, navigate to ./terraform
and run the following to initialize your Terraform state:
terraform init
./gradlew build
Then build the shadow jar for the Lambda:
./gradlew api-aws-lambda:shadowJar
These steps assume you have already initialized Terraform as described in "Infrastructure Setup" above.
- Ensure you have the AWS CLI configured, working, and pointing to the default AWS account you wish to deploy to.
- Ensure you've run the "Build" step above
cd
to theterraform
folder in this repo- Run
terraform plan
to see what changes will be applied to your AWS account - Run
terraform apply -auto-approve
to make the changes and deploy the server. - When the Terraform scripts are updated or you wish to redeploy, repeat steps 7 and 8.
The API Gateway root URL will be echoed to the shell, and you can CURL the deployed API:
curl -X POST https://e6f2c4llfk.execute-api.us-west-1.amazonaws.com/v4/tcnreport -d "ZXlKMFpYTjBJam9pWW05a2VTSjk="
curl -X GET https://e6f2c4llfk.execute-api.us-west-1.amazonaws.com/v4/tcnreport
For running the server on your developer AWS account, follow the steps below under AWS Insfrastructure Setup section.
For testing the lambda function and API locally, you can use SAM CLI. Below docs should be helpful.
Swagger Definition and API documentation is located under api_definition folder:
The API can be tested by pasting the definition on Swagger Editor
Method | HTTP request | Description |
---|---|---|
tcnreportPost | POST /tcnreport | Submit symptom or infection report following TCN 0.4.0 protocol |
tcnreportGet | GET /tcnreport?date={report_date}?intervalNumber={interval}?intervalLengthMs={interval_length_ms} | Returns a list of reports generated on the specified date and interval |