A prototype API that supports storage of applications for criminal legal aid.
The API is powered by Amazon API Gateway, AWS Lambda and Amazon DynamoDB. Involved resources are defined and provisioned using AWS SAM.
- API - see
/dist/openapi.json
for the API spec, test from Swagger UI. - Lambda functions - see
/aws/lambda
for read and write handlers.
You can run and test the application locally using AWS SAM.
- Node.js 12 or above
- npm 6 or above
- Docker
- AWS CLI and AWS SAM CLI
- Create a network
docker network create my-network
- Run a dynamodb container in it
docker run -d --network my-network -v "$PWD":/dynamodb_local_db -p 8000:8000 \ --network-alias=dynamodb --name dynamodb \ amazon/dynamodb-local -jar DynamoDBLocal.jar -sharedDb
- Create table
aws dynamodb create-table --cli-input-yaml file://./aws/local-dynamo.yml --endpoint-url http://localhost:8000
- Verify table created
aws dynamodb list-tables --endpoint-url http://localhost:8000 aws dynamodb describe-table --table-name applications-for-criminal-legal-aid-dev --endpoint-url http://localhost:8000
- Seed table with test items
sam local invoke WriteCrimeApplications -e aws/events/dynamo-seed-applications.json --docker-network my-network
- Confirm items created
sam local invoke ReadCrimeApplications -e aws/events/api-fetch-applications.json --docker-network my-network
You can either invoke lambda functions directly using test events, or start a local instance of the API to test request/response functionality.
a) Invoking Lambda functions directly
- You can test each lambda with dummy events:
- Write lambda example:
sam local invoke WriteCrimeApplications -e aws/events/api-submit-application.json --docker-network my-network
- Read lambda example:
sam local invoke ReadCrimeApplications -e aws/events/api-fetch-applications.json --docker-network my-network
- Set the test event data using the
-e
flag and use-d 5858
to run in debug mode.
b) Making API requests
- Start a local instance of API gateway
sam local start-api --docker-network my-network
- Call the API at
http://127.0.0.1:3000/applications
staging
- updates are auto-deployed tostaging
environment on push/merge tomain
branch. See./github/workflows
.dev
- you can deploy manually using SAM cli- Package your lambda functions and store them in S3.
sam package --s3-bucket crime-apply-api-dynamo-lambda --s3-prefix sam --output-template-file out.yml
- Deploy a new version of your app using the artifacts the command above just generated (using dev as the stage, for example)
sam deploy --template-file out.yml --capabilities CAPABILITY_IAM --guided --stack-name crime-applications-dev --parameter-overrides Stage=dev
- Follow the promtps, using the default vales (for dev deploy) and entering the version numbers of the lambda code (versions are set in
aws/lambda/[name-of-lambda]/package.json
).
- Package your lambda functions and store them in S3.
See template.yml
for the SAM template.