-
Notifications
You must be signed in to change notification settings - Fork 129
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
Upgrade Code to AWS SDK v3 #409
base: master
Are you sure you want to change the base?
Conversation
lib/backend.js
Outdated
function loadDynamoConfig(env) { | ||
const dynamoConfig = { | ||
endpoint: 'http://localhost:8000', | ||
sslEnabled: false, | ||
region: 'us-east-1', | ||
accessKeyId: 'key', | ||
secretAccessKey: env.AWS_SECRET_ACCESS_KEY || 'secret' | ||
region: 'us-east-1' | ||
} | ||
|
||
loadDynamoEndpoint(env, dynamoConfig) | ||
|
||
if (AWS.config) { | ||
if (AWS.config.region !== undefined) { | ||
dynamoConfig.region = AWS.config.region | ||
} | ||
|
||
if (AWS.config.credentials) { | ||
if (AWS.config.credentials.accessKeyId !== undefined) { | ||
dynamoConfig.accessKeyId = AWS.config.credentials.accessKeyId | ||
} | ||
} | ||
} | ||
|
||
if (env.AWS_REGION) { | ||
dynamoConfig.region = env.AWS_REGION | ||
} | ||
|
||
if (env.AWS_ACCESS_KEY_ID) { | ||
dynamoConfig.accessKeyId = env.AWS_ACCESS_KEY_ID | ||
} | ||
|
||
return dynamoConfig | ||
} | ||
|
||
const createAwsConfig = (AWS) => { | ||
const createAwsConfig = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm running dynamodb on port 8042 locally. Running
DYNAMO_ENDPOINT=http://localhost:8042 nr dev --port 8002
on this branch and opening http://0.0.0.0:8002 results in error:
CredentialsProviderError: Could not load credentials from any providers
I suppose because the default access key and secret are no longer specified?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry it took me a while to respond.
Yeah it is failing when there are no credentials configured locally.
By default it would follow the sdk and search for creds
I added a new flag to set dummy creds if we do not have local credentials. (--dummy_creds, -D) Feel free to try again and review 😄 @rchl |
bin/dynamodb-admin.js
Outdated
parser.add_argument('-D', '--dummy_creds', { | ||
action:'store_true', | ||
required: false, | ||
help: 'Use dummy AWS credentials', | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For it not to be a breaking change, it would need to by default use dummy credentials.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah , I spent a bunch of time thinking about that.
Makes sense to default it to true
@@ -38,15 +38,16 @@ parser.add_argument('-p', '--port', { | |||
help: 'Port to run on (default: 8001)', | |||
}) | |||
|
|||
parser.add_argument('-D', '--dummy_creds', { | |||
parser.add_argument('-l', '--local_config', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's more common to use dashes in command line options instead of underscores.
@@ -46,41 +46,41 @@ function loadDynamoEndpoint(env, dynamoConfig) { | |||
* @param AWS - the AWS SDK object | |||
* @returns {{endpoint: string, sslEnabled: boolean, region: string, accessKeyId: string}} | |||
*/ | |||
function loadDynamoConfig(env, isDummy) { | |||
function loadDynamoConfig(env, local_config) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
camelCase
convention is being used in Javascript
Any update on this? |
@@ -405,7 +405,7 @@ | |||
|
|||
if (data.Items.length) { | |||
$('#items-container').append(data.Items.map(item => { | |||
const viewUrl = '/tables/<%= Table.TableName %>/items/' + encodeURIComponent(Object.values(item.__key).join(',')) | |||
const viewUrl = '/tables/<%= Table.TableName %>/items/' + encodeURIComponent(Object.values(Object.values(item.__key)[0]).join(',')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran this locally for my dataset, and this doesn't work properly when there are multiple keys involved, as this is only picking the first key.
I fixed this locally by doing:
Object.values(item.__key).map(function (i) { return Object.values(i)[0] }).join(',')
What:
Upgrade AWS SDK from v2 to v3
WHY:
Incompatibility with Node 18 based platforms as AWS SDK v2 does not work well.
Note:
Thanks to this PR from @garrettheel.
I used your idea of converting the
CapacityUnits
intoNumber
which saved me some work.