Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

vikasperi
Copy link

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 into Number which saved me some work.

lib/backend.js Outdated
Comment on lines 49 to 60
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 = () => {
Copy link
Collaborator

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?

Copy link
Author

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

@vikasperi
Copy link
Author

vikasperi commented Nov 22, 2023

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

Comment on lines 41 to 45
parser.add_argument('-D', '--dummy_creds', {
action:'store_true',
required: false,
help: 'Use dummy AWS credentials',
})
Copy link
Collaborator

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.

Copy link
Author

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

@vikasperi vikasperi requested a review from rchl November 23, 2023 02:47
@@ -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', {
Copy link
Collaborator

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) {
Copy link
Collaborator

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

@zaun
Copy link

zaun commented Mar 22, 2024

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(','))

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(',')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants