Skip to content

Commit

Permalink
prepping app for distro
Browse files Browse the repository at this point in the history
  • Loading branch information
Grant Moore committed Feb 5, 2022
1 parent 43c1972 commit 62d3428
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 143 deletions.
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,28 @@ document.save()
```

## Setup
### From PyPi

TODO

### From Source
Overview
--------

### Overview
1. (Optional) Configure environment
2. Create **QLDB** Ledger
3. Configure IAM user/role permissions for ledger
4. Install library

### Steps

Steps
-----
1. (Optional) Configure Environment

```shell
cp ./env/.sample.env ./env/.env
export LEDGER='ledger-name'
```

The environment variable **LEDGER** should point to the **QLDB** ledger. If you do not configure the **LEDGER** environment variable, you will need to pass in the ledger name to the `Document` object. See [below](#documents) for more information.

2. Create **QLDB** Ledger

A **QLDB** CloudFormation template is available in the *cf* directory of this project. A script has been provided to post this template to **CloudFormation**, assuming your [AWS CLI has been authenticated and configured](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html). From the project root, execute the following script and specify the `<ledger-name>` to create a ledger on QLDB,
A **QLDB** CloudFormation template is available in the *cf* directory of this project's [Github](https://github.com/Makpar-Innovation-Laboratory/innolqb). A script has been provided to post this template to **CloudFormation**, assuming your [AWS CLI has been authenticated and configured](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html). Clone the repository and then rrom the project root, execute the following script and specify the `<ledger-name>` to create a ledger on the QLDB service,

```shell
./scripts/qldb-stack --ledger <ledger-name>
./scripts/cf-stack --ledger <ledger-name>
```

**NOTE**: The `<ledger-name>` must match the value of the **LEDGER** environment variable. The name of the ledger that is stood up on AWS is passed to the library through this environment variable.
Expand All @@ -53,6 +47,11 @@ In production, you will want to limit the permissions of the application client

If you are configuring an application role to use this library for a particular ledger and table, you will need to scope the permissions using [this reference](https://docs.aws.amazon.com/qldb/latest/developerguide/getting-started-standard-mode.html).

4. Install `innolqb`

```shell
pip install innolqb
```

## Documents

Expand Down Expand Up @@ -103,4 +102,10 @@ Behind the scenes, whenever the `save()` method is called, a query is run to che
## References
- [AWS QLDB Documentation](https://docs.aws.amazon.com/qldb/latest/developerguide/what-is.html)
- [QLDB Python Driver Documentation](https://amazon-qldb-driver-python.readthedocs.io/en/stable/index.html)
- [PartiQL Documentation](https://partiql.org/docs.html)
- [PartiQL Documentation](https://partiql.org/docs.html)

## TODOS

1. Provision QLDB through Boto3 client instead of using CloudFormation template; i.e., make the provisioning of the Ledger part of the library.

2. Query class to return iterable of Documents.
14 changes: 2 additions & 12 deletions cf/qldb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,14 @@ Description: "Stack for a serverless QLDB ledger"
Parameters:
ledgerName:
Type: String
applicationName:
Type: String
Default: innolab
environmentName:
Type: String
Default: Dev
Default: laboratory

Resources:
QLDBLedger:
Type: AWS::QLDB::Ledger
Properties:
Name: !Sub ${applicationName}-${environmentName}-${ledgerName}
Name: !Ref ledgerName
PermissionsMode: STANDARD
DeletionProtection: false
Tags:
- Key: Environment
Value: !Ref environmentName
- Key: Application
Value: !Ref applicationName


8 changes: 2 additions & 6 deletions env/.sample.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# STACK CONFIGURATION
APPLICATION=innolab
ENVIRONMENT=Dev

# LIBRARY CONFIGURATION
LEDGER=innolab-Dev-test
# APPLICATION CONFIGURATION
LEDGER=innolab-laboratory
DEFAULT_INDEX=id
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
51 changes: 51 additions & 0 deletions scripts/cf-stack
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
SCRIPT_NAME="qldb-stack"
SCRIPT_DES=$'A script for posting QLDB template to CloudFormation. See comments in script for usage information.'
PROJECT_DIR=$SCRIPT_DIR/..
source $PROJECT_DIR/env/.env

# Example Usage:
# >$ qldb-stack> --ledger

function log(){
echo -e "\e[92m$(date +"%r")\e[0m: \e[4;32m$SCRIPT_NAME\e[0m : >> $1"
}

function help(){
echo -e "\n\e[4m$SCRIPT_NAME\e[0m\n\n\t$SCRIPT_DES"
}

while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--ledger|-ledger|--l|-l)
LEDGER="$2"
shift
shift
;;
--help|-help|--h|-h)
help
exit 0
;;
*)
log "Input not understood. See \e[3m--help\e[0m for information on using this command."
exit 1
;;
esac
done

if [ -z "$LEDGER" ]
then
log "No \e[3m--ledger\e[0m specified. Re-execute with this required argument."
exit 1
fi

cp $PROJECT_DIR/cf/qldb.yml ./qldb.yml
log "Creating \e[1mQLDB-${LEDGER}-Stack\e[0m"
aws cloudformation create-stack \
--stack-name "QLDB-${LEDGER}-Stack" \
--template-body file://qldb.yml \
--parameters ParameterKey=ledgerName,ParameterValue=$LEDGER
rm ./qldb.yml
109 changes: 0 additions & 109 deletions scripts/qldb-stack

This file was deleted.

4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ project_urls =
[options]
python_requires = >= 3.8
package_dir=
=innolqb
=innoldb
packages=find:
install_requires =
amazon.ion >=0.9.1
pyqldb >=3.2.2
python-dotenv >=0.19.2

[options.packages.find]
where=innolqb
where=innoldb

0 comments on commit 62d3428

Please sign in to comment.