Skip to main content

DocumentDB API Example

Project description

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'}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docdbdemo-0.1.0a6.tar.gz (751.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docdbdemo-0.1.0a6-py3-none-any.whl (749.2 kB view details)

Uploaded Python 3

File details

Details for the file docdbdemo-0.1.0a6.tar.gz.

File metadata

  • Download URL: docdbdemo-0.1.0a6.tar.gz
  • Upload date:
  • Size: 751.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.5

File hashes

Hashes for docdbdemo-0.1.0a6.tar.gz
Algorithm Hash digest
SHA256 27ef93cb0ee4820d7a4404a0073ab0ef23ccd628def4d8f9b17991d052288cb5
MD5 ece8be596a06f81bb83744db57036560
BLAKE2b-256 6b7fb746dfdd5a38efce506149dee79ac96fe625b025c50469c0ce132d57e9c2

See more details on using hashes here.

File details

Details for the file docdbdemo-0.1.0a6-py3-none-any.whl.

File metadata

  • Download URL: docdbdemo-0.1.0a6-py3-none-any.whl
  • Upload date:
  • Size: 749.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.5

File hashes

Hashes for docdbdemo-0.1.0a6-py3-none-any.whl
Algorithm Hash digest
SHA256 923a0e4cc4284c607caf45750eb1c5b983556692ce5ba513931b7e7e21064c80
MD5 2d6e1423496a188d0dfc2b56238eb422
BLAKE2b-256 538bdbe512101a2064c47d56d601f70c3fb8716bd2666469ccc8ac088a84e221

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page