Skip to content

Commit 96135cf

Browse files
committed
fix #17: when AWS_SDK_LOAD_CONFIG is set and ~/.aws doesn't exist BOOM
This appears to be a bug upstream as a result of aws/aws-sdk-js#1391 We now check for the presence of ~/.aws prior to setting this env-var.
1 parent d6ef203 commit 96135cf

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/cli.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1+
import * as path from 'path';
2+
import * as fs from 'fs';
13
import * as process from 'process';
2-
// We need to set this early because of https://github.com/aws/aws-sdk-js/pull/1391
3-
process.env.AWS_SDK_LOAD_CONFIG = '1';
4+
5+
const awsUserDir = process.env.HOME ? path.join(process.env.HOME as string, '.aws') : null;
6+
if (awsUserDir && fs.existsSync(awsUserDir)) {
7+
// We need to set this early because of https://github.com/aws/aws-sdk-js/pull/1391
8+
// We also set this env-var in the main cli entry-point
9+
process.env.AWS_SDK_LOAD_CONFIG = '1'; // see https://github.com/aws/aws-sdk-js/pull/1391
10+
// Note:
11+
// if this is set and ~/.aws doesn't exist we run into issue #17 as soon as the sdk is loaded:
12+
// Error: ENOENT: no such file or directory, open '.../.aws/credentials
13+
}
14+
415
// Use bluebird promises globally. We need to load this prior to 'aws-sdk'
516
import * as bluebird from 'bluebird';
617
global.Promise = bluebird;

src/configureAWS.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
import * as process from 'process';
2-
process.env.AWS_SDK_LOAD_CONFIG = '1'; // see https://github.com/aws/aws-sdk-js/pull/1391
3-
// We also set this env-var in the main cli entry-point
42

53
import * as fs from 'fs';
64
import * as path from 'path';
5+
6+
const awsUserDir = process.env.HOME ? path.join(process.env.HOME as string, '.aws') : null;
7+
if (awsUserDir && fs.existsSync(awsUserDir)) {
8+
// We also set this env-var in the main cli entry-point
9+
process.env.AWS_SDK_LOAD_CONFIG = '1'; // see https://github.com/aws/aws-sdk-js/pull/1391
10+
// Note:
11+
// if this is set and ~/.aws doesn't exist we run into issue #17 as soon as the sdk is loaded:
12+
// Error: ENOENT: no such file or directory, open '.../.aws/credentials
13+
}
14+
15+
import * as _ from 'lodash';
716
import * as aws from 'aws-sdk';
817

918
import {logger} from './logger';

0 commit comments

Comments
 (0)