This is split into the following components:
Component | Description |
---|---|
Backend | Written in Go 1.16 and will run as an AWS Lambda function. This function can also be called by an API |
Deploy | Terraform scripts to deploy the api and go code to AWS cloud |
All code can be found in the backend/
folder of this repo
Every commit to this repo will trigger a Github Action to build and test the code.
To build/test locally:
cd backend/
go mod tidy
go build .
go test .
The deployment is handled through terraform scripts.
Terraform scripts configure the following:
- Go Lambda with the pack calc deployed
- Node Lambda used as an authoriser for the API Gateway
- API Gateway integrated with the pack calc lambda
- A randomly generated token stored as a secure string in
ParamterStore
which is used as the auth token
The API only supports on endpoint as a POST request.
The API body is JSON and should look like this example:
{
"items":501,
"packSizes": [250,500,1000,2000,5000]
}
Example Request:
curl -X POST --data '{"items":501, "packSizes": [250,500,1000,2000,5000]}' \
https://jcwz2ki77i.execute-api.eu-west-2.amazonaws.com/calculate-packs -H "Authorization: qD449xM9k0nvK@_f"
The auth token is just an example
- Unfortunately, I did not have enough time to implement a frontend as I was learning golang while implementing the backend
- GitHub Actions have been used to do the following:
- Build and Test the Go Lang Code
- Terraform script validation (
fmt
,init
andvalidate
) - On a PR merge, a GitHub release is created with the compiled Go code attached
- Once a GitHub release is published, a deployment workflow is triggered.
- This workflow will handle the deployment of the resources