Coder Social home page Coder Social logo

dynamodb's Introduction

dynamodb

ci

DynamoDB client.

Usage

import { createClient } from "https://denopkg.com/chiefbiiko/dynamodb/mod.ts";

// if config/credentials not passed they will be read from the env/fs
const dyno = createClient();

// the client has all of DynamoDB's operations as camelCased async methods
const result = await dyno.listTables();

The client config can be omitted entirely when calling createClient. If that is the case the config will be derived from the environment and filesystem, in that order, using get-aws-config.

Prefer using temporary credentials and a session token.

API

Contents

  1. Basics

  2. Factory

  3. Ops

Basics

/** Generic document. */
export interface Doc {
  [key: string]: any;
}

/** Generic representation of a DynamoDB client. */
export interface DynamoDBClient {
  describeEndpoints: (options?: Doc) => Promise<Doc>;
  describeLimits: (options?: Doc) => Promise<Doc>;
  listTables: (options?: Doc) => Promise<Doc>;
  scan: (
    params: Doc,
    options?: Doc
  ) => Promise<Doc | AsyncIterableIterator<Doc>>;
  query: (
    params: Doc,
    options?: Doc
  ) => Promise<Doc | AsyncIterableIterator<Doc>>;
  [key: string]: (params: Doc, options?: Doc) => Promise<Doc>;
}

/** Credentials. */
export interface Credentials {
  accessKeyId: string; // AKIAIOSFODNN7EXAMPLE
  secretAccessKey: string; // wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
  sessionToken?: string; // somesessiontoken
}

/** Client configuration. */
export interface ClientConfig {
  credentials?: Credentials | (() => Credentials | Promise<Credentials>);
  region?: string; // us-west-2
  profile?: string; // default
  canonicalUri?: string; // fx /path/to/somewhere
  port?: number; // 80
  host?: string; // localhost
}

/** Op options. */
export interface OpOptions {
  wrapNumbers?: boolean, // wrap numbers to a special number value type? [false]
  convertEmptyValues?: boolean, // convert empty strings and binaries? [false]
  translateJSON?: boolean, // translate I/O JSON schemas? [true]
  iteratePages?: boolean // if a result is paged, async-iterate it? [true]
}

Factory

createClient

createClient(conf: ClientConfig): DynamoDBClient

Creates a DynamoDB client.

Ops

The client supports all DynamoDB operations. Check the linked aws docs for info about parameters of a specific operation.

BatchGetItem

batchGetItem(params: Doc, options?: OpOptions): Promise<Doc>

aws BatchGetItem docs

BatchWriteItem

batchWriteItem(params: Doc, options?: OpOptions): Promise<Doc>

aws BatchWriteItem docs

CreateBackup

createBackup(params: Doc, options?: OpOptions): Promise<Doc>

aws CreateBackup docs

CreateGlobalTable

createGlobalTable(params: Doc, options?: OpOptions): Promise<Doc>

aws CreateGlobalTable docs

CreateTable

createTable(params: Doc, options?: OpOptions): Promise<Doc>

aws CreateTable docs

DeleteBackup

deleteBackup(params: Doc, options?: OpOptions): Promise<Doc>

aws DeleteBackup docs

DeleteItem

deleteItem(params: Doc, options?: OpOptions): Promise<Doc>

aws DeleteItem docs

DeleteTable

deleteTable(params: Doc, options?: OpOptions): Promise<Doc>

aws DeleteTable docs

DescribeBackup

describeBackup(params: Doc, options?: OpOptions): Promise<Doc>

aws DescribeBackup docs

DescribeContinuousBackups

describeContinuousBackups(params: Doc, options?: OpOptions): Promise<Doc>

aws DescribeContinuousBackups docs

DescribeEndpoints

describeEndpoints(options?: OpOptions): Promise<Doc>

aws DescribeEndpoints docs

DescribeGlobalTable

describeGlobalTable(params: Doc, options?: OpOptions): Promise<Doc>

aws DescribeGlobalTable docs

DescribeGlobalTableSettings

describeGlobalTableSettings(params: Doc, options?: OpOptions): Promise<Doc>

aws DescribeGlobalTableSettings docs

DescribeLimits

describeLimits(options?: OpOptions): Promise<Doc>

aws DescribeLimits docs

DescribeTable

describeTable(params: Doc, options?: OpOptions): Promise<Doc>

aws DescribeTable docs

DescribeTimeToLive

describeTimeToLive(params: Doc, options?: OpOptions): Promise<Doc>

aws DescribeTimeToLive docs

GetItem

getItem(params: Doc, options?: OpOptions): Promise<Doc>

aws GetItem docs

ListBackups

listBackups(params: Doc, options?: OpOptions): Promise<Doc>

aws ListBackups docs

ListGlobalTables

listGlobalTables(params: Doc, options?: OpOptions): Promise<Doc>

aws ListGlobalTables docs

ListTables

listTables(options?: OpOptions): Promise<Doc>

aws ListTables docs

ListTagsOfResource

listTagsOfResource(params: Doc, options?: OpOptions): Promise<Doc>

aws ListTagsOfResource docs

PutItem

putItem(params: Doc, options?: OpOptions): Promise<Doc>

aws PutItem docs

Query

query(params: Doc, options?: OpOptions): Promise<Doc | AsyncIterableIterator<Doc>>

aws Query docs

RestoreTableFromBackup

restoreTableFromBackup(params: Doc, options?: OpOptions): Promise<Doc>

aws RestoreTableFromBackup docs

RestoreTableToPointInTime

restoreTableToPointInTime(params: Doc, options?: OpOptions): Promise<Doc>

aws RestoreTableToPointInTime docs

Scan

scan(params: Doc, options?: OpOptions): Promise<Doc | AsyncIterableIterator<Doc>>

aws Scan docs

TagResource

tagResource(params: Doc, options?: OpOptions): Promise<Doc>

aws TagResource docs

TransactGetItems

transactGetItems(params: Doc, options?: OpOptions): Promise<Doc>

aws TransactGetItems docs

TransactWriteItems

transactWriteItems(params: Doc, options?: OpOptions): Promise<Doc>

aws TransactWriteItems docs

UntagResource

untagResource(params: Doc, options?: OpOptions): Promise<Doc>

aws UntagResource docs

UpdateContinuousBackups

updateContinuousBackups(params: Doc, options?: OpOptions): Promise<Doc>

aws UpdateContinuousBackups docs

UpdateGlobalTable

updateGlobalTable(params: Doc, options?: OpOptions): Promise<Doc>

aws UpdateGlobalTable docs

UpdateGlobalTableSettings

updateGlobalTableSettings(params: Doc, options?: OpOptions): Promise<Doc>

aws UpdateGlobalTableSettings docs

UpdateItem

updateItem(params: Doc, options?: OpOptions): Promise<Doc>

aws UpdateItem docs

UpdateTable

updateTable(params: Doc, options?: OpOptions): Promise<Doc>

aws UpdateTable docs

UpdateTimeToLive

updateTimeToLive(params: Doc, options?: OpOptions): Promise<Doc>

aws UpdateTimeToLive docs

FYI

Don't want to do all development against the real AWS cloud?

License

MIT

dynamodb's People

Contributors

alxblsk avatar chiefbiiko avatar hayd avatar revgum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

dynamodb's Issues

possible to make this lib like dynamoose?

dynamoose is for node to use dynaomodb in serverless lambda.

I see this lib use all like native aws js sdk to call with dynaomodb...
I am looking for something like deno version of dynamoose

Thanks.

Assume Role With Web Identity Provider

Is it possible assume role rather than explicitly providing the credentials?

Context: When running on Kubernetes (EKS), we use a Kubernetes ServiceAccount. We don't even have these values: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN. Instead we have AWS_ROLE_ARN and AWS_WEB_IDENTITY_TOKEN_FILE. So for example, when using boto3, it automagically detects this and handles assuming the role.

boto3 Assume Role With Web Identity Provider

EKS Docs IAM roles for service accounts

Support AWS_SESSION_TOKEN

For example in aws lambda, in order for the client to work it needs to pass the header (if it exists):

    "X-Amz-Security-Token": Deno.env("AWS_SESSION_TOKEN"),

in createHeaders. Note this is a short-lived token so likely this has to be looked up each time anyways (I don't think this can be cached)...

I can confirm this fix works for deno+dynamodb on aws lambda ๐ŸŽ‰ but perhaps there is a better way to do it from a style/testing point of view?


Aside: Without this fix the underlying request gives a "The security token included in the request is invalid." error, but you don't see that without modifying the dynamodb code just Error: http query request failed: 400 Bad Request, it'd be great to bubble up the json error message (which was googleable / suggested this solution).

Credential must have exactly 5 slash-delimited elements

Simple test:

import { createClient } from "https://raw.githubusercontent.com/mbonig/dynamodb/master/mod.ts";

const ddb = createClient({port:443});

const results = await ddb.listTables();

Results in this error:


error: Uncaught Error: Credential must have exactly 5 slash-delimited elements, e.g. keyid/date/region/service/term, got '/'

Note the above code uses a slight modification of this module due to the other issues I've mentioned previously.

how to connect to local dynamo DB in docker compose?

Hi,
it can connect to separate dynamoDB, while when all the service and DynamoDB in one docker compose, then local seems not work,
maybe need to update some logic update fixed localhost when region is local?

Use deno.land in deps.ts

Unfortunately I often see denopkg.com 504 somewhat frequently in ci.
I think it would make sense to move your deps to deno.land.

(It's a shame there isn't a clean way to same domain e.g. if you get dynamodb from denopkg then all it's dependencies are denopkg, and same for deno.land.)

How to putItem or updateItem with conditional expression?

Hi. first of all im not really good at deno, typescript and dynamodb. i just want to learn something new. so I manage to connect and put an item to my table. but I wonder how will I do it with conditional expression. I look on the docs and test file but I cant find any example on how to do it using this package.

It would be great if anyone can help and show me how can I updateItem or putItem with conditional express with its values.

thank you in advance

Error when package getting installed

I'm getting below error when dynamodb package getting installed..

`PS G:\AWS Workspace\deno-rest> deno run --allow-net .\denoserver.ts
Download https://denopkg.com/chiefbiiko/dynamodb/mod.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/mod.ts
Compile https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/mod.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/client/mod.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/util.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/util.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/client/aws_signature_v4.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/client/base_op.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/client/derive_config.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/client/create_headers.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/client/translator.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/deps.ts
Download https://denopkg.com/chiefbiiko/[email protected]/mod.ts
Download https://denopkg.com/chiefbiiko/[email protected]/mod.ts
Download https://denopkg.com/chiefbiiko/[email protected]/mod.ts
Download https://deno.land/x/[email protected]/mod.ts
Download https://denopkg.com/chiefbiiko/[email protected]/mod.ts
Download https://raw.githubusercontent.com/chiefbiiko/std-encoding/v1.0.0/mod.ts
Download https://raw.githubusercontent.com/chiefbiiko/hmac/v1.0.2/mod.ts
Download https://raw.githubusercontent.com/chiefbiiko/sha256/v1.0.2/mod.ts
Download https://raw.githubusercontent.com/chiefbiiko/get-aws-config/v0.3.5/mod.ts
Download https://deno.land/x/base64/base64url.ts
Download https://deno.land/x/base64/base.ts
Download https://raw.githubusercontent.com/chiefbiiko/hmac/v1.0.2/deps.ts
Download https://denopkg.com/chiefbiiko/[email protected]/mod.ts
Download https://denopkg.com/chiefbiiko/[email protected]/mod.ts
Download https://raw.githubusercontent.com/chiefbiiko/sha1/v1.0.3/mod.ts
Download https://raw.githubusercontent.com/chiefbiiko/sha512/v1.0.3/mod.ts
Download https://raw.githubusercontent.com/chiefbiiko/sha1/v1.0.3/deps.ts
Download https://raw.githubusercontent.com/chiefbiiko/sha256/v1.0.2/deps.ts
Download https://raw.githubusercontent.com/chiefbiiko/sha512/v1.0.3/deps.ts
Download https://deno.land/x/[email protected]/base.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/client/base_fetch.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/api/mod.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/api/api.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/api/collection.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/api/operation.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/api/shape.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/client/converter.ts
Download https://raw.githubusercontent.com/chiefbiiko/dynamodb/master/client/create_cache.ts
error TS2339: Property 'dir' does not exist on type 'typeof Deno'.
const HOME: string = Deno.dir("home") ?? "";
~~~
at https://raw.githubusercontent.com/chiefbiiko/get-aws-config/v0.3.5/mod.ts:11:27

error TS2349: This expression is not callable.
Type '{ get(key: string): string | undefined; set(key: string, value: string): void; toObject(): { [index: string]: string; }; }' has no call signatures.
const ENV: { [key: string]: any; } = _opts.env ? Deno.env() : {};
~~~
at https://raw.githubusercontent.com/chiefbiiko/get-aws-config/v0.3.5/mod.ts:90:57

Found 2 errors.`

Support 1.0.0

There have been a bunch of breaking code changes which affect dynamodb (and dependencies).

Would be great to have this working for 1.0.0 !

hygiene: simplify codebase

api/*
client/translator|converter.ts

use classes
n get rid of those prop declarators
correct and narrow typings

Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'

It looks like since Deno 1.5, there was a breaking change which is causing an issue. I'm running Deno 1.17.2 and seeing this error:

error: TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { Doc } from "./util.ts";
         ~~~
    at https://denopkg.com/chiefbiiko/[email protected]/mod.ts:5:10

TS1205 [ERROR]: Re-exporting a type when the '--isolatedModules' flag is provided requires using 'export type'.
export { HeadersConfig, createHeaders } from "./create_headers.ts";
         ~~~~~~~~~~~~~
    at https://denopkg.com/chiefbiiko/[email protected]/client/mod.ts:4:10

Found 2 errors.

I found some solutions saying to create a tsconfig.json like this:

{
  "compilerOptions": {
    "isolatedModules": false,
  }
}

... but it did not solve the issue.

A bit more research turned up this saying that isolatedModules cannot be disabled: denoland/deno#12599

error deriving credentials

Right now I have access keys setup in a standard (default) profile in my ~/.aws/config and ~/.aws/credentials files. When I use the get-aws-config dependency directly I can see it properly retrieving all my credential information correctly. However, when trying to .createClient I get this error:

error: Uncaught Error: unable to derive aws config

Here at this line: https://github.com/chiefbiiko/dynamodb/blob/master/client/derive_config.ts#L27

Looking through the current code it looks like the derive_config.ts is expecting access key and secret to sit on a "credentials" field, where 'got' currently returns those directly on the return object.

Have access_key_id , secret_access_key, and session_token share their lifecycle

currently, sessionToken is updateable as the module calls conf.sessionToken anytime it sets it in a request. Nonetheless, key id and access key are still static and not updateable during runtime. Using temporary credentials in a long running process is thus not really possible at the moment..
A fix could fx put a credentials getter on client config:

/** Credentials. */
export interface Credentials {
    accessKeyId: string; // AKIAIOSFODNN7EXAMPLE
    secretAccessKey: string; // wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
    sessionToken: string; // somesessiontoken
}

/** Client configuration. */
export interface ClientConfig {
  credentials(): Credentials | Promise<Credentials>;
  region: string; // us-west-2
  canonicalUri?: string; // fx /path/to/somewhere
  port?: number; // 80
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.