Skip to content

abhisheksarolia/track-n-trace-usng-qldb

Repository files navigation

Build an end-to-end application to track goods in a supply chain using Amazon QLDB

Today, companies build complex and custom mechanisms to achieve traceability inside supply chain systems. Instead of building custom ledger functionality on a traditional database system, you can take advantage of Amazon Quantum Ledger Database (Amazon QLDB) to record the history of each transaction in an immutable way on an Amazon QLDB journal. Amazon QLDB helps eliminate the need to engage in the complex development effort of building your ledger-like functionality in applications. With QLDB, the history of changes to your data is immutable—it can't be altered, updated, or deleted.

In this post, we propose a solution to address a key challenge in the pharmaceutical supply chain around tracking and validating the authenticity of manufactured drugs that require strict cold chain storage during the entire supply chain. You can adopt these concepts to implement product traceability into other kinds of sophisticated supply chains as well.

The following figure depicts the reference architecture of solution.

Architecture

Prerequisites and Setup

The quick deployment of the solution is using AWS Cloud Development Kit (AWS CDK) to create the resources required for this post, such as Amazon API Gateway endpoint, AWS Lambda functions, Amazon Quantum Ledger Database(Amazon QLDB), AWS Identity and Access Management (IAM) role, related permission policies and optional components - Amazon Cognito user pool, and AWS IoT thing with associated rule and permissions.

You can use AWS Cloud9, a cloud-based integrated development environment, to complete the actions or run the setup locally on a Windows or Mac workstation/laptop. If you are running the set up locally then install and configure following toolset –

AWS CLINode.jsPythonTypeScriptAWS CDK for TypeScriptPostman or Curl

We are using AWS Cloud9 to set up and run the project, which comes pre-installed with all the above tooling. Follow below steps for solution setup -

  1. Clone the code from GitHub repo on Cloud 9 terminal shell
git clone https://github.com/abhisheksarolia/track-n-trace-usng-qldb.git

cd track-n-trace-usng-qldb/
  1. The AWS CDK includes a library of AWS constructs called the AWS Construct Library, organized into various modules. The library contains constructs for each AWS service. Install the main CDK package for TypeScript –
npm install aws-cdk-lib  
  1. Create new directory & install required dependency modules from the “requirements.txt” using python package manager-
mkdir sharedLib
mkdir sharedLib/python

pip install -r requirements.txt -t ./sharedLib/python  
  1. Create an IAM role with administrator access and attach the role on cloud9 instance. You can use this deep link to create the role with administrator access.

  2. Validate the CDK version on your Cloud9 instance –

cdk –-version

If the output of above command comes as “2.80.0”, then upgrade the CDK to “2.81.0”

npm install -g [email protected] --force 

Validate the version again to make sure CDK version is upgraded.

cdk –-version 
  1. Synthesize the CDK template.
cdk synth

The first time you deploy an AWS CDK app into an environment (account/region), you install a “bootstrap stack”. This stack includes resources that are used in the toolkit’s operation. For example, the stack includes an S3 bucket that is used to store templates and assets during the deployment process.

  1. You can use “cdk bootstrap” command to install the bootstrap stack into an environment –
cdk bootstrap
  1. Deploy the stack –
cdk deploy

Once the stack deployment completes, verify created resources in the AWS console under CloudFormation stacks with the name “TrackntraceCdkStack”

For invoking API in this post, we will use Postman but you can invoke API via curl also. Go ahead and install Postman locally from here.

Clean Up:

  1. Destroy the resources -
cdk destroy 
  1. Edit QLDB delete protection from AWS Console and delete that on UI or run below aws CLI command
aws qldb delete-ledger --name trackntrace-using-qldb

About

track-n-trace-usng-qldb

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published