# copy-dynamodb-table

> Copy Dynamodb table to another in the same or different zone , It is 100% safe , and speed depends on your destination table user defined write provisioned throughput

Latest version **2.2.1** (published 2021-02-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install copy-dynamodb-table
pnpm add copy-dynamodb-table
yarn add copy-dynamodb-table
bun add copy-dynamodb-table
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.1 |
| Published | 2021-02-24 |
| First published | 2017-05-24 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 16.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 131 |
| Author | Ezzat @enGMzizo |
| Maintainers | engmzizo |
| Keywords | dynamodb, aws-dynamodb, AWS, copy-tables |

## Links

- npm: https://www.npmjs.com/package/copy-dynamodb-table
- Repository: https://github.com/enGMzizo/copy-dynamodb-table
- Homepage: https://github.com/enGMzizo/copy-dynamodb-table#readme
- Issues: https://github.com/enGMzizo/copy-dynamodb-table/issues
- npm.io page: https://npm.io/package/copy-dynamodb-table

## Dependencies (2)

- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.630.0
- [readline](https://npm.io/package/readline.md) ^1.3.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 2.2.1 (latest) — 2021-02-24
- 2.2.0 — 2021-02-24
- 2.1.0 — 2021-02-19
- 2.0.20 — 2020-04-26
- 2.0.19 — 2020-04-07
- 2.0.18 — 2020-02-29
- 2.0.17 — 2019-05-08
- 2.0.16 — 2019-04-21
- 2.0.15 — 2019-04-21
- 2.0.14 — 2018-11-05
- 2.0.13 — 2018-04-29
- 2.0.12 — 2018-04-29
- 2.0.11 — 2018-04-25
- 2.0.10 — 2018-04-18
- 2.0.9 — 2018-03-12
- … 16 more at https://npm.io/package/copy-dynamodb-table/versions

## README

Safe Copy Dynamodb Table
===================

This module will allow you to copy data from one table to another using very simple API, Support cross zone copying and AWS config for each table ( source & destination ) and it can create the destination table using source table schema

[![Dependencies](https://david-dm.org/enGMzizo/copy-dynamodb-table.png)](https://david-dm.org/enGMzizo/copy-dynamodb-table) [![NPM version](https://badge.fury.io/js/copy-dynamodb-table.png)](http://badge.fury.io/js/copy-dynamodb-table)


## Installation

    npm i copy-dynamodb-table

## Usage :

```js
var copy = require('copy-dynamodb-table').copy

copy({
    source: {
      tableName: 'source_table_name', // required
    },
    destination: {
      tableName: 'destination_table_name', // required
    },
    log: true, // default false
    create : true, // create destination table if not exist
    schemaOnly : false, // if true it will copy schema only -- optional
    continuousBackups: true, // if true will enable point in time backups
    transform: function(item , index){ return item } // function to transform data
  },
  function (err, result) {
    if (err) {
      console.log(err)
    }
    console.log(result)
  })
```
## Adding AWS Config :

```js
var copy = require('copy-dynamodb-table').copy

var globalAWSConfig = { // AWS Configuration object http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#constructor-property
  accessKeyId: 'AKID',
  secretAccessKey: 'SECRET',
  region: 'eu-west-1'
}

copy({
    config: globalAWSConfig, // config for AWS
    source: {
      tableName: 'source_table_name', // required
    },
    destination: {
      tableName: 'destination_table_name', // required
    },
    log: true, // default false
    create : true // create destination table if not exist
  },
  function (err, result) {
    if (err) {
      console.log(err)
    }
    console.log(result)
  })
```

## AWS Config for each table ( cross region ) :

```js
var copy = require('copy-dynamodb-table').copy

var globalAWSConfig = { // AWS Configuration object http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#constructor-property
  accessKeyId: 'AKID',
  secretAccessKey: 'SECRET',
  region: 'eu-west-1'
}

var sourceAWSConfig = {
  accessKeyId: 'AKID',
  secretAccessKey: 'SECRET',
  region: 'eu-west-1'
}

var destinationAWSConfig = {
  accessKeyId: 'AKID',
  secretAccessKey: 'SECRET',
  region: 'us-west-2' // support cross zone copying
}

copy({
    config: globalAWSConfig,
    source: {
      tableName: 'source_table_name', // required
      config: sourceAWSConfig // optional , leave blank to use globalAWSConfig
    },
    destination: {
      tableName: 'destination_table_name', // required
      config: destinationAWSConfig // optional , leave blank to use globalAWSConfig
    },
    log: true,// default false
    create : true // create destination table if not exist
  },
  function (err, result) {
    if (err) {
      console.log(err)
    }
    console.log(result)
  })
```

## Note :

  - If `source.config` or `destination.config` value is `undefined` , the module will use the `globalAWSConfig`.
  - If `globalAWSConfig` value is `undefined` the module will extact `AWS` config from environment variables.
  - Increase Write capacity for your dynamodb table temporarily until the copying is finished so you can get the highest copying speed

## Promise version :

Use this if you want to copy using promises, or async / await .

```javascript
function promiseCopy(data) {
  return new Promise((resolve, reject) => {
    copy(data, function (err, result) {
      if (err) {
        return reject(err)
      }
      resolve(result)
    })
  })
}

promiseCopy({
  source: {
    tableName: 'source_table_name', // required
  },
  destination: {
    tableName: 'destination_table_name', // required
  },
  log: true, // default false
  create: true // create destination table if not exist
}).then(function (results) {
  // do stuff
}).catch(function (err) {
  //handle error
})
```

## Use Case :
  With source table read capacity units = 100 & destination table write capacity units  = 1000 , I managed to copy ~100,000 items from source to destination within ~175 seconds , with avarage item size of 4 KB.

## Contributors :

- [@enGMzizo](https://twitter.com/enGMzizo)
- [jazarja](https://github.com/jazarja)
- [kevpmoore](https://github.com/kevpmoore)
- [Floby](https://github.com/Floby)
- [jermeo](https://github.com/jermeo)
- [Simon Li](https://github.com/siutsin)
- [Janusz Slota](https://github.com/nixilla)
- [Kyle Watson](https://github.com/kylejwatson)

## License :

[ISC](https://spdx.org/licenses/ISC)

---
_Source: https://npm.io/package/copy-dynamodb-table · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
