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

UnrecognizedClientException #212

Open
skilbjo opened this issue Jul 3, 2023 · 7 comments
Open

UnrecognizedClientException #212

skilbjo opened this issue Jul 3, 2023 · 7 comments
Assignees

Comments

@skilbjo
Copy link

skilbjo commented Jul 3, 2023

Have been using @shelf/jest-dynamodb for 2 yrs and just started getting this error in github actions (not locally)

    UnrecognizedClientException: The Access Key ID or security token is invalid.

      at Request.extractError (node_modules/aws-sdk/lib/protocol/json.js:52:27)
      at Request.callListeners (node_modules/aws-sdk/lib/sequential_executor.js:106:20)
      at Request.emit (node_modules/aws-sdk/lib/sequential_executor.js:78:10)
      at Request.emit (node_modules/aws-sdk/lib/request.js:686:14)
      at Request.transition (node_modules/aws-sdk/lib/request.js:22:10)
      at AcceptorStateMachine.runTo (node_modules/aws-sdk/lib/state_machine.js:14:12)
      at node_modules/aws-sdk/lib/state_machine.js:26:10
      at Request.<anonymous> (node_modules/aws-sdk/lib/request.js:38:9)
      at Request.<anonymous> (node_modules/aws-sdk/lib/request.js:688:12)
      at Request.callListeners (node_modules/aws-sdk/lib/sequential_executor.js:116:18)
      at Request.emit (node_modules/aws-sdk/lib/sequential_executor.js:78:10)
      at Request.emit (node_modules/aws-sdk/lib/request.js:686:14)
      at Request.transition (node_modules/aws-sdk/lib/request.js:22:10)
      at AcceptorStateMachine.runTo (node_modules/aws-sdk/lib/state_machine.js:14:12)
      at node_modules/aws-sdk/lib/state_machine.js:26:10
      at Request.<anonymous> (node_modules/aws-sdk/lib/request.js:38:9)
      at Request.<anonymous> (node_modules/aws-sdk/lib/request.js:688:12)
      at Request.callListeners (node_modules/aws-sdk/lib/sequential_executor.js:116:18)
      at callNextListener (node_modules/aws-sdk/lib/sequential_executor.js:96:12)
      at IncomingMessage.onEnd (node_modules/aws-sdk/lib/event_listeners.js:335:13)

package.json

...
    "@shelf/jest-dynamodb": "3.4.1",
    "aws-sdk": "2.1046.0",
...

test/file.test.ts

  const localClient = new AWS.DynamoDB({
    credentials: {
      accessKeyId: 'fake-access-key',
      secretAccessKey: 'fake-secret-access-key',
    },
    endpoint,
    region: 'local',
    sslEnabled: false,
  });
...

src/file.ts

...
  dynamo
    .putItem(<AWS.DynamoDB.PutItemInput>{
      ...(!overwrite && { ConditionExpression: 'attribute_not_exists(PK)' }), // if overwrite is true, the ConditionExpression is omitted
      Item: item,
      TableName: tableName,
    })
    .promise();
...

github actions:

jobs:
  publish-artifact:
    permissions:
      issues: write
    runs-on: ubuntu-latest
    timeout-minutes: 10
    steps:
      - uses: actions/checkout@v3
        with:
          token: ${{ secrets.ACTIONS_TOKEN }}
          persist-credentials: false
      - uses: actions/setup-node@v3
        with:
          node-version: 16 

...
@skilbjo
Copy link
Author

skilbjo commented Jul 3, 2023

this just started happening as of 29 June; without any code changes.

I go back to a working build, click "re-run jobs" and it fails w the above error. So I think it's something to do with github actions.

Anyways opening a thread here to see if anyone has come up w a workaround

@0aprl1
Copy link

0aprl1 commented Jul 3, 2023

My team just suffered the same issue. One of my teammates realized that when initializing dynamodb-local, we were downloading the latest version from AWS repo. We now have pinned to the latest working version, dynamodb_local_2023-06-09.tar.gz, and the issue is solved.

@skilbjo
Copy link
Author

skilbjo commented Jul 3, 2023

@0aprl1

could you expand? how did you get it to work? can you share the code sample of your workaround?

@slmarcos
Copy link

slmarcos commented Jul 4, 2023

@skilbjo
I just setup this config on my config file

  installerConfig: {
    downloadUrl: 'https://s3.eu-central-1.amazonaws.com/dynamodb-local-frankfurt/dynamodb_local_2023-06-09.tar.gz'
  }

@skilbjo
Copy link
Author

skilbjo commented Jul 4, 2023

great! thanks for that. and just to clarify, here's where it goes:

jest-dynamodb-config.js

module.exports = {
  // https://github.com/shelfio/jest-dynamodb/issues/212
  installerConfig: {
    downloadUrl:
      'https://s3.eu-central-1.amazonaws.com/dynamodb-local-frankfurt/dynamodb_local_2023-06-09.tar.gz',
  },

i will leave the issue open in case the maintainer wants to address, but ^^^ is a valid workaround atm

@rommelcapa
Copy link

rommelcapa commented Jul 6, 2023

Same issue here. What worked for us was "installing" an older version of dynamodb-local before running the unit test.

module.exports = {
  installerConfig: {
    installPath: '.dynamodb',
  },
}
#!/bin/sh
curl -O https://d1ni2b6xgvw0s0.cloudfront.net/dynamodb_local_2023-06-09.tar.gz <-- this is where the link goes from AWS in my part of the world. Chose the same file from @skilbjo above
mkdir -p .dynamodb && mv dynamodb_local_2023-06-09.tar.gz .dynamodb/
tar -xvf .dynamodb/dynamodb_local_2023-06-09.tar.gz -C .dynamodb/
npm run test

You can add checks not to run the above commands everytime you run the test.

@venkatesh-kl
Copy link

venkatesh-kl commented Mar 11, 2024

For anyone who is facing this issue, this is the fix which resolved the issues for me. Add below logic to your jest-dynamodb-config.js:
jest-dynamodb-config.js before the fix:

module.exports = {
  // standard table configuration, ports etc
};

Solution:

module.exports = {
  // defaulting to a release of dynamodb as latest version needs some changes to the environment variables
  // References: https://github.com/shelfio/jest-dynamodb/issues/212
  // https://repost.aws/articles/ARc4hEkF9CRgOrw8kSMe6CwQ/troubleshooting-the-access-key-id-or-security-token-is-invalid-error-after-upgrading-dynamodb-local-to-version-2-0-or-greater
 installerConfig: {
    downloadUrl: 'https://s3.eu-central-1.amazonaws.com/dynamodb-local-frankfurt/dynamodb_local_2023-06-09.tar.gz',
  },
    // standard table configuration, ports etc
};

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

No branches or pull requests

6 participants