diff --git a/README.md b/README.md index c3bc273..63d2008 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ Repository containing code for a self-contained service to generate unique "references" for records transferred to The National Archives (TNA). +![](https://raw.githubusercontent.com/nationalarchives/tdr-dev-documentation/master/beta-architecture/diagrams/reference-generator.svg) + The service consists of three main components: * *Lambda function*: the Lambda generates the "references" based on a incremented counter; * *DynamoDb Table*: the table contains the counter to generate the unique "references"; @@ -9,15 +11,37 @@ The service consists of three main components: ## Lambda -[TODO] +The lambda contains the code for generating references. +This Lambda function is triggered by an api gateway event and context object. It retrieves the current value of the counter from DynamoDB, increments it, +and stores the updated value back in DynamoDB. It then generates a unique “reference” using the counter value. Finally, it returns the generated “references” json to the caller like so: +`[ +"M3H5J", +"M3H5K" +]` + +A 500 response body will be returned if any issues occur when calling the Lambda for example +* numberofrefs exceeds the limit +* numberofrefs parameter isn't an int +* any dynamodb Exceptions (key not found, unable to update, etc) ## DynamoDb Table -[TODO] +The DynamoDb stores the current counter used for generating unique references. The DynamoDb is encrypted so that it cannot be directly modified via the AWS console or AWS CLI. +Below is an example of what the table looks like: + +| v1 | referenceCounter | +|-------------|------------------| +| fileCounter | 6 | + ## API Gateway -[TODO] +The API Gateway provides a RESTful interface to the Lambda function. +The urls for calling the reference generator can be obtained from the [da-terraform-configurations](https://github.com/nationalarchives/da-terraform-configurations/blob/main/tdr/main.tf#L35-L37) +It can be called directly by providing the parameter `numberofrefs={value}` by making a http request to one of the reference generator urls, for example: +`https://j8ezi9m4z0.execute-api.eu-west-2.amazonaws.com/intg/counter?numberofrefs=2`. + +The api gateway has a resource policy which restricts which services can call it. ## Deployment @@ -57,8 +81,22 @@ The reference counter in the DynamoDb table needs to be manually seeded before t ### Terraform -[TODO] +The Terraform directory contains the Terraform code used to create the DynamoDb, Lambda and API Gateway resources. +It relies on the `da-terraform-configurations` and `da-terraform-modules` projects. + +1. Clone DA Terraform Configurations repository + + ``` + [location of project] $ git clone https://github.com/nationalarchives/da-terraform-configurations.git + ``` + +2. Clone DA Terraform Modules repository + + ``` + [location of project] $ git clone https://github.com/nationalarchives/da-terraform-modules.git + ``` -### Lambda Code +#### Apply Terraform +Commit and push all the changes made in the terraform directory to its GitHub repo, then (in the GitHub repo): -[TODO] +Go the Actions tab -> Click ["Apply Terraform and deploy lambda"] -> Click "Run workflow" -> select the branch with the workflow file you want to use -> type the version to deploy -> Click the green "Run worklfow" button diff --git a/terraform/da-terraform-configurations b/terraform/da-terraform-configurations index 1b90976..43e57c2 160000 --- a/terraform/da-terraform-configurations +++ b/terraform/da-terraform-configurations @@ -1 +1 @@ -Subproject commit 1b90976a36bd6bb5784bf08592b8efc420f2834b +Subproject commit 43e57c284c1cdb3367b4b126926dd08e36b31ae5 diff --git a/terraform/da-terraform-modules b/terraform/da-terraform-modules index baa17c1..c2b9fad 160000 --- a/terraform/da-terraform-modules +++ b/terraform/da-terraform-modules @@ -1 +1 @@ -Subproject commit baa17c11018e96f7b9077a17dd9fd1e764e9fca4 +Subproject commit c2b9fad96cacf15e252609ba60c3e0d3253739eb