Skip to content

Development code to show simple CRUD operations on Amazon QLDB and setup Amazon Kinesis Data streams. The solution uses AWS Lambda Amazon API Gateway Amazon QLDB Amazon DynamoDB and Amazon Kinesis Data Streams

License

Notifications You must be signed in to change notification settings

aws-samples/amazon-qldb-financialwallet-crud-aws-samples-v2

Repository files navigation

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. SPDX-License-Identifier: MIT-0

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Build a simple CRUD operation & Data streams on Amazon QLDB using AWS Lambda, API Gateway, Amazon DynamoDB, Amazon Kinesis Data streams

Protected Source with compensation liability. Patent pending. Update May 31 2023

Solution Overview

This demonstrates following Serverless solutions to create a virtual financial wallet solution.

DISCLAIMER: Before you install

  • The stack installation deploys in US-EAST-1 of AWS Cloud. Resources will be consumed beyond the FREE-TIER.
  • Cleanup steps are provided below to delete resources that are created by the stack. Refer CLEANUP section
  • This is a prototype only for testing and education.
  • Deploy and Test at your own risks and no claims can be made to the owner for consumption billing, performances or anything that the stack creates or deletes.
  • The application stack ships without any support
  • You should have basic understanding of computer programming

Pre-Requisite Installation

  1. Signup for AWS account. Resources will be consumed beyond the FREE-TIER.
  2. Serverless framework relies on node js runtime in your IDE. Install Node JS latest version.

Verify and proceed when your version verification is complete.

$ node -v
v14.17.5
$ npm -v
6.14.14
  1. Install the latest version of AWS CLI

Confirm the installation and proceed.

`$ aws --version 
aws-cli/2.1.29 Python/3.7.4 Linux/4.14.133-113.105.amzn2.x86_64 botocore/2.0.0`
  1. Configure your AWS credentials by following instructions here.

*Note:The fastest way to get started with Serverless is to create an IAM user with Administrator Access. This IAM user will have full access to your AWS account and should not be used for your company's production AWS account. The best approach here is to create a new AWS account *with limited ability to affect other resources. This will give you the widest latitude to experiment with Serverless without getting tangled in a web of IAM permissions.

$ aws configure

configure with AWS Access key and secrey as per the documentation above

AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default region name [None]: us-east-1 Default output format [None]: json

  1. Install AWS SAM by following instructions here

Verify the installation and proceed


$ sam --version
SAM CLI, version 1.19.0
  1. Install git (to download the application stack), Follow steps here

Verify the installation and proceed.

$ git —version
git version 2.32.0

DEPLOYMENT

Clone the code repo from github

  1. Create a directory in your local machine
  2. Within the directory run the following command
$ git clone 

Note: if you dont have git installed, please follow the instructions here Your file tree structure should look like this in the current directory

.
├── api
│   ├── capmywallet-qldb.js
│   └── package.json
├── events
│   └── event.json
├── package.json
├── README.md
├── samconfig.toml
├── template.yaml

  1. Run the following command from the location of “template.yaml”

$ sam build

  1. Run the following command from the location of “template.yaml” after the build succeds

$ sam deploy -g —capabilities CAPABILITY_NAMED_IAM

Verify the deployed services

The above deployment will deploy the following services

Verify API end points (sample below)

POST - https://sampleurl.amazonaws.com/Prod/createtable/
GET  - https://sampleurl.amazonaws.com/Prod/index/
POST - https://sampleurl.amazonaws.com/Prod/createaccount/
POST - https://sampleurl.amazonaws.com/Prod/checkfunds/
POST - https://sampleurl.amazonaws.com/Prod/addfunds/
POST - https://sampleurl.amazonaws.com/Prod/withdrawfunds/

Verify Resources

QLDB Ledger. Access Amazon QLDB from AWS Management Console→ Change your region (default deploys in us-east-1))

LedgerName: captable1

DynamoDB Table. Access Amazon QLDB from AWS Management Console→ Change your region (default deploys in us-east-1)

TableName: captable1

Kinesis data stream. Access Amazon Kinesis from AWS Management Console→ Change your region (default deploys in us-east-1)

Data Stream Name: captable1-kinesis-stream

IAM role. Access IAM rom AWS Management Console→ Change your region (default deploys in us-east-1)

QLDB Kinesis Stream role name: captableStream-*accountid**-**region*
Lambda role : capmywallet-west2-1148-funds-*region-*lambdaRole

Test you Data Stream from QLDB

  • Sign in to the AWS Management Console, and open the Amazon QLDB console at https://console.aws.amazon.com/qldb.
  • In the navigation pane, choose Streams.
  • Click on “catable1-qldb-stream”
  • Verify the details like Record aggregation, Destination and Analyse the Stream metrics

Test your CRUD operations (refer to the AWS blog post)

Cleanup

If you no longer need to use the captable1 ledger after completing your testing, from your directory in the shell run the below command (same directory as “sam deploy” command)

$ aws cloudformation delete-stack --region <REGIONDEPLOYED> --stack-name <STACKNAME>

THERE WILL BE NO OUTPUT OF THE COMMAND. Alternatively, Yon can log into AWS Management Console→ Cloudformation to check the progress of the deletion of the stack

Conclusion

Hopefully this was informative. If you need help please message private or drop email to the author

About

Development code to show simple CRUD operations on Amazon QLDB and setup Amazon Kinesis Data streams. The solution uses AWS Lambda Amazon API Gateway Amazon QLDB Amazon DynamoDB and Amazon Kinesis Data Streams

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published