JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q31302F
  • License Apache-2.0

DocumentDB API Example

Package Exports

  • @richardhboyd/doc_db_lib

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@richardhboyd/doc_db_lib) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Amazon DocumentDB Demo Construct


Installing

Pypi (Python)

pip install docdbdemo

npm (JavaScript and TypeScript)

npm install @richardhboyd/doc_db_lib


Usage

Python

from aws_cdk import (
    core
)
from docdbdemo import DocDbLib


class MyStack(core.Stack):

    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        DocDbLib(self, "MyDocDBClient")

TypeScript

import cdk = require('@aws-cdk/core');
import docdbdemo = require('@richardhboyd/doc_db_lib');

export class DocDbClientTsStack extends cdk.Stack {
  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new docdbdemo.DocDbLib(this, "MyDocDBClient");
  }
}

Diagram


Interacting

Deploying the stack will create an Amazon DocumentDB Cluster with one instance in each availability zone created by the CDK's VPC Construct, a Lambda function that can put items into the database and fetch them out again, and an API to send requests to the Lambda Funciton.

The stack will output an APIGateway endpoint that will front the created DocumentDB.

Outputs:
DocDbClientTsStack.MyDocDBClientMyDocDbApiMyDocDBApiEndpoint74609B36 = https://gv8ooq7zti.execute-api.us-east-1.amazonaws.com/prod/

Let's look at how we use this new API.

Putting a document in the DocumentDB

API=https://gv8ooq7zti.execute-api.us-east-1.amazonaws.com/prod
curl -H "Content-Type: application/json" -d '{"bestCoder":"@allenmichael", "worstCoder":"singledigit"}' -X POST $API/document

Getting a document out of the database

API=https://gv8ooq7zti.execute-api.us-east-1.amazonaws.com/prod
curl -H "Content-Type: application/json" $API/document?bestCoder=@allenmichael

Testing this out we see

$ curl -H "Content-Type: application/json" -d '{"bestCoder":"@allenmichael", "worstCoder":"@singledigit"}' -X POST $API/document

{"id": "5d7bd032c7866a33171a1261"}

$ curl -H "Content-Type: application/json" $API/document?bestCoder=@allenmichael

{'_id': ObjectId('5d7bcfe6c7866a33171a125f'), 'bestCoder': '@allenmichael', 'worstCoder': '@singledigit'}