diff --git a/README.md b/README.md index c6f7aaf..483e534 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/bin/dynamodb-admin.ts b/bin/dynamodb-admin.ts index ea01d45..d1e1ce1 100755 --- a/bin/dynamodb-admin.ts +++ b/bin/dynamodb-admin.ts @@ -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.', }); @@ -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; @@ -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}`);