Gymshark API
shipping-package-size-calculator lambda - Responsible for calculating the number of packs gymshark needs to ship to the customer.
- Go 1.21+
- Terraform v1.6+
- AWS CLI
- golangci-lint
- govulncheck
At the root path of the gymshark-api, run the following command to execute the unit tests
make test
The PACKAGE_SIZES environment variable is a required configuration that contains a list of package sizes. While an initial value is provided during Terraform provisioning, this approach offers flexibility by allowing modifications to package sizes without altering the implementation. As a next step, consider transitioning to a database table for managing package sizes.
For deploying the lambda function to AWS cloud provider, you have to create a aws profile called gymshark-aws.
aws configure --profile gymshark-aws
After configuring your AWS profile, you can execute the following command to deploy the function to the cloud provider, making it ready for use.
make run-terraform
After deployment, Terraform will provide the Lambda function endpoint:
lambda_function_url = "https://lyqy2yvqi6rak3edlus5ne47fi0vigqk.lambda-url.us-east-1.on.aws/"
curl -X POST -H "Content-Type: application/json" -d '{"numberOfItemsOrdered": 12001}' https://lyqy2yvqi6rak3edlus5ne47fi0vigqk.lambda-url.us-east-1.on.aws/
RESPONSE BODY:
{
"data": [
{
"quantity": 2,
"size": 5000,
"isFull": true
},
{
"quantity": 1,
"size": 2000,
"isFull": true
}
],
"success": true,
"status": 200
}
curl -X POST -H "Content-Type: application/json" -d '{"numberOfItemsOrdered": 2}' https://lyqy2yvqi6rak3edlus5ne47fi0vigqk.lambda-url.us-east-1.on.aws/
RESPONSE BODY:
{
"success": false,
"message": "No complete packages found for the given number of items",
"status": 404
}