This repo contains server and infrastructure code for deploying and running CoEpi Cloud API on AWS.
There are two API frontends provided: an AWS Lambda (api-aws-lambda) and a standalone server (api-server). For more information on running the standalone server, see api-server/README.md.
- Compute: AWS Lambda OR any container-based solution
- 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.localIn a terminal, navigate to ./terraform and run the following to initialize your Terraform state:
terraform init./gradlew buildThen build the shadow jar for the Lambda:
./gradlew api-aws-lambda:shadowJarThese 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
cdto theterraformfolder in this repo- Run
terraform planto see what changes will be applied to your AWS account - Run
terraform apply -auto-approveto 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:
h0NRnh3cJgUtHeI3oycAsJhWPsechtfiDyxkKQun9sV9lO0LhZfRRm4sMYGoSSOEBjj9qhGbvSookL/pBUkTwhQAKAAACkhpZ2ggRmV2ZXIOOyQmkj5pi/bM0Uo/h/4RxwH2wrN094GIOAQgMBCs8rCByJlxUqp+ZAJqgev2hC56nSHxbH0stERKps5GFI8E
curl -X POST https://e6f2c4llfk.execute-api.us-west-1.amazonaws.com/v4/tcnreport/0.4.0 -d "<Base64 encoded report data>"
curl -X GET https://e6f2c4llfk.execute-api.us-west-1.amazonaws.com/v4/tcnreport/0.4.0For 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/0.4.0 | Submit symptom or infection report following TCN 0.4.0 protocol |
| tcnreportGet | GET /tcnreport/0.4.0?intervalNumber={intervalNumber}?intervalLength={interval_length_seconds} | Returns a list of reports generated on the specified interval |