Skip to content

add aws session param #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Can be run as a command line script or as an npm module.
--aws-key AWS access key. Will use AWS_ACCESS_KEY_ID env var if --aws-key not set
--aws-secret AWS secret key. Will use AWS_SECRET_ACCESS_KEY env var if --aws-secret not set
--aws-region AWS region. Will use AWS_DEFAULT_REGION env var if --aws-region not set
--aws-session <sessionToken> AWS session Token. Will use AWS_SESSION_TOKEN env var if --aws-session not set
```

# npm module usage
Expand All @@ -46,6 +47,7 @@ var backup = new DynamoBackup({
awsAccessKey: /* AWS access key */,
awsSecretKey: /* AWS secret key */,
awsRegion: /* AWS region */
awsSessionToken: /* AWS Session Token */
});

backup.on('error', function(data) {
Expand Down Expand Up @@ -83,6 +85,7 @@ var options = {
awsAccessKey: /* AWS access key */,
awsSecretKey: /* AWS secret key */,
awsRegion: /* AWS region */,
awsSessionToken: /* AWS Session Token */,
backupPath: /* folder to save backups in. default: 'DynamoDB-backup-YYYY-MM-DD-HH-mm-ss',
base64Binary: /* whether or not to base64 encode binary data before saving to JSON */
};
Expand Down Expand Up @@ -186,6 +189,7 @@ Can be run as a command line script or as an npm module.
--aws-key <key> AWS access key. Will use AWS_ACCESS_KEY_ID env var if --aws-key not set
--aws-secret <secret> AWS secret key. Will use AWS_SECRET_ACCESS_KEY env var if --aws-secret not set
--aws-region <region> AWS region. Will use AWS_DEFAULT_REGION env var if --aws-region not set
--aws-session <sessionToken> AWS session Token. Will use AWS_SESSION_TOKEN env var if --aws-session not set
```

## Examples
Expand Down Expand Up @@ -238,7 +242,8 @@ var restore = new DynamoRestore({
concurrency: 200, // for large restores use 1 unit per MB as a rule of thumb (ie 1000 for 1GB restore)
awsAccessKey: /* AWS access key */,
awsSecretKey: /* AWS secret key */,
awsRegion: /* AWS region */
awsRegion: /* AWS region */,
awsSessionToken: /* AWS Session Token */
});

restore.on('error', function(message) {
Expand Down Expand Up @@ -275,7 +280,8 @@ var options = {
stopOnFailure: /* true/false should a single failed batch stop the whole restore job? */,
awsAccessKey: /* AWS access key */,
awsSecretKey: /* AWS secret key */,
awsRegion: /* AWS region */
awsRegion: /* AWS region */,
awsSessionToken: /* AWS Session Token */
};

var restore = new DynamoBackup.Restore(options);
Expand Down
2 changes: 2 additions & 0 deletions bin/dynamo-backup-to-s3
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ program
.option('--aws-key <key>', 'AWS access key. Will use AWS_ACCESS_KEY_ID env var if --aws-key not set')
.option('--aws-secret <secret>', 'AWS secret key. Will use AWS_SECRET_ACCESS_KEY env var if --aws-secret not set')
.option('--aws-region <region>', 'AWS region. Will use AWS_DEFAULT_REGION env var if --aws-region not set')
.option('--aws-session <sessionToken>', 'AWS session Token. Will use AWS_SESSION_TOKEN env var if --aws-session not set')
.parse(process.argv);

// run program
Expand All @@ -39,6 +40,7 @@ var dynamoBackup = new DynamoBackup({
awsAccessKey: program.awsKey,
awsSecretKey: program.awsSecret,
awsRegion: program.awsRegion,
awsSessionToken: program.awsSession,
backupPath: program.backupPath,
bucket: program.bucket,
excludedTables: program.excludedTables,
Expand Down
2 changes: 2 additions & 0 deletions bin/dynamo-restore-from-s3
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ program
.option('--aws-key <key>', 'AWS access key. Will use AWS_ACCESS_KEY_ID env var if --aws-key not set')
.option('--aws-secret <secret>', 'AWS secret key. Will use AWS_SECRET_ACCESS_KEY env var if --aws-secret not set')
.option('--aws-region <region>', 'AWS region. Will use AWS_DEFAULT_REGION env var if --aws-region not set')
.option('--aws-session <sessionToken>', 'AWS session Token. Will use AWS_SESSION_TOKEN env var if --aws-session not set')
.parse(process.argv);

// Display help if needed
Expand Down Expand Up @@ -49,6 +50,7 @@ var dynamoRestore = new DynamoRestore({
awsKey: program.awsKey,
awsSecret: program.awsSecret,
awsRegion: program.awsRegion,
awsSession: program.awsSession
});

function translate(contentLength) {
Expand Down
4 changes: 4 additions & 0 deletions lib/dynamo-backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function DynamoBackup(options) {
this.awsAccessKey = options.awsAccessKey;
this.awsSecretKey = options.awsSecretKey;
this.awsRegion = options.awsRegion;
this.awsSessionToken = options.awsSessionToken;
this.debug = Boolean(options.debug);

if (this.awsRegion) {
Expand All @@ -34,6 +35,9 @@ function DynamoBackup(options) {
params.accessKeyId = this.awsAccessKey;
params.secretAccessKey = this.awsSecretKey;
}
if (this.awsSessionToken) {
params.sessionToken = this.awsSessionToken;
}

AWS.config.update(params);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/dynamo-restore.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ function DynamoRestore(options) {
options.awsKey = options.awsKey || process.env.AWS_ACCESS_KEY_ID;
options.awsSecret = options.awsSecret || process.env.AWS_SECRET_ACCESS_KEY;
options.awsRegion = options.awsRegion || process.env.AWS_DEFAULT_REGION || 'ap-southeast-2';
options.awsSessionToken = options.awsSessionToken || process.env.AWS_SESSION_TOKEN;

AWS.config.update({
accessKeyId: options.awsKey,
secretAccessKey: options.awsSecret,
region: options.awsRegion
region: options.awsRegion,
sessionToken: options.awsSessionToken
});

this.options = options;
Expand Down