Skip to content

Commit

Permalink
fix: ensure DYNAMO_ENDPOINT env overwrites default endpoint when set (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
rchl authored Nov 18, 2024
1 parent 19260d2 commit 07c9c17
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Options:
- `--dynamo-endpoint` - DynamoDB endpoint to connect to (default: http://localhost:8000).
- `--skip-default-credentials` - Skip setting default credentials and region. By default the accessKeyId/secretAccessKey are set to "key" and "secret" and the region is set to "us-east-1". If you specify this argument then you need to ensure that credentials are provided some other way. See https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials-node.html for more details on how default credentials provider works.

Environment variables `HOST`, `PORT` and `DYNAMO_ENDPOINT` can also be used to set the respective options. Those are not recommended.
Environment variables `HOST`, `PORT` and `DYNAMO_ENDPOINT` can also be used to set the respective options.

If you use a local dynamodb that cares about credentials, you can configure them by using the following environment variables `AWS_REGION` `AWS_ACCESS_KEY_ID` `AWS_SECRET_ACCESS_KEY` or specify the `--skip-default-credentials` argument and rely on the default AWS SDK credentials resolving behavior.

Expand Down
14 changes: 6 additions & 8 deletions bin/dynamodb-admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ parser.add_argument('-o', '--open', {

parser.add_argument('-H', '--host', {
type: 'str',
required: false,
default: process.env.HOST || undefined,
help: 'Host to run on (default: undefined)',
});

parser.add_argument('-p', '--port', {
type: 'int',
default: 8001,
default: process.env.PORT ?? 8001,
help: 'Port to run on (default: 8001)',
});

parser.add_argument('--dynamo-endpoint', {
type: 'str',
default: 'http://localhost:8000',
default: process.env.DYNAMO_ENDPOINT || 'http://localhost:8000',
help: 'DynamoDB endpoint to connect to.',
});

Expand All @@ -51,13 +51,11 @@ parser.add_argument('--skip-default-credentials', {
const { host, port, open: openUrl, dynamo_endpoint: dynamoEndpoint, skip_default_credentials: skipDefaultCredentials } = parser.parse_args();

const app = createServer({ dynamoEndpoint, skipDefaultCredentials });
const resolvedHost = process.env.HOST || host;
const resolvedPort = process.env.PORT || port;
const server = app.listen(resolvedPort, resolvedHost);
const server = app.listen(port, host);
server.on('listening', () => {
const address = server.address();
if (!address) {
throw new Error(`Not able to listen on host and port "${resolvedHost}:${resolvedPort}"`);
throw new Error(`Not able to listen on host and port "${host}:${port}"`);
}
let listenAddress;
let listenPort;
Expand All @@ -68,7 +66,7 @@ server.on('listening', () => {
listenPort = address.port;
}
let url = `http://${listenAddress}${listenPort ? ':' + listenPort : ''}`;
if (!resolvedHost && listenAddress !== '0.0.0.0') {
if (!host && listenAddress !== '0.0.0.0') {
url += ` (alternatively http://0.0.0.0:${listenPort})`;
}
console.info(` dynamodb-admin listening on ${url}`);
Expand Down

0 comments on commit 07c9c17

Please sign in to comment.