Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Resources for an API for criminal legal aid applications (prototype)

License

Notifications You must be signed in to change notification settings

ministryofjustice/laa-crime-apply-prototype-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

laa-crime-apply-prototype-api

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.

Architecture

Components

  • API - see /dist/openapi.json for the API spec, test from Swagger UI.
  • Lambda functions - see /aws/lambda for read and write handlers.

Local development

You can run and test the application locally using AWS SAM.

Pre-requisites:

  • Node.js 12 or above
  • npm 6 or above
  • Docker
  • AWS CLI and AWS SAM CLI

Setup Docker:

  • 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

Setup database:

  • 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

Testing locally

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

Deployment

  • staging - updates are auto-deployed to staging environment on push/merge to main 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).

See template.yml for the SAM template.

About

Resources for an API for criminal legal aid applications (prototype)

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published