freshollie / jest-dynalite

Jest preset to run Dynalite (DynamoDB local) per test runner
https://www.npmjs.com/package/jest-dynalite
MIT License
151 stars 16 forks source link

`Could not load credentials from any providers` on GitHub Actions #76

Open taschetto opened 2 years ago

taschetto commented 2 years ago

I'm using jest-dynalite to test my DynamoDB operations. This is the code I'm using to initialize the client.

const { DynamoDB } = require('@aws-sdk/client-dynamodb')
const { DynamoDBDocument } = require('@aws-sdk/lib-dynamodb')

const config = {
  region: process.env.AWS_REGION,
  ...(process.env.MOCK_DYNAMODB_ENDPOINT && {
    endpoint: process.env.MOCK_DYNAMODB_ENDPOINT,
    sslEnabled: false,
    region: 'local',
  }),
}

const client = new DynamoDB(config)
const document = DynamoDBDocument.from(client)

module.exports = {
  client,
  document,
}

The tests are passing in my local environment and my code is working as expected in production (AWS lambda). Sadly, the tests are failing on CI (GitHub Actions):

FAIL src/utils.test.js
  ● getQueryParamsFromEvent › should mount parameters from a well formed event

    CredentialsProviderError: Could not load credentials from any providers

      at providers (node_modules/@aws-sdk/credential-provider-node/dist-cjs/index.js:25:19)
      at node_modules/@aws-sdk/property-provider/dist-cjs/chain.js:11:28
      at coalesceProvider (node_modules/@aws-sdk/property-provider/dist-cjs/memoize.js:13:24)
      at SignatureV4.credentialProvider (node_modules/@aws-sdk/property-provider/dist-cjs/memoize.js:32:24)
      at SignatureV4.signRequest (node_modules/@aws-sdk/signature-v4/dist-cjs/SignatureV4.js:84:29)
      at node_modules/@aws-sdk/middleware-signing/dist-cjs/middleware.js:13:18
      at StandardRetryStrategy.retry (node_modules/@aws-sdk/middleware-retry/dist-cjs/StandardRetryStrategy.js:51:46)
      at node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:6:22
          at async Promise.all (index 0)

My workflow is correctly setting up the environment variables:

  my-project:
    runs-on: ubuntu-20.04
    steps:
      - name: Configure AWS Credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.CI_AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.CI_AWS_SECRET_ACCESS_KEY }}
          aws-region: ${{env.AWS_REGION}}
          role-to-assume: ci-github
          role-external-id: ci-github
          role-duration-seconds: 3600
          role-session-name: ${{ github.job }}-${{ github.run_id }}-${{ github.run_number}}
      - name: Checkout Code
        uses: actions/checkout@v2
      - name: Install Dependencies
        run: yarn install
      - name: Run Unit Tests
        run: yarn test

Are there any additional steps for this to work? Thanks for your help.

freshollie commented 2 years ago

Don't understand this one. Did you manage to get any further?

James1218 commented 1 year ago

@taschetto HI, I'm having the same error CredentialsProviderError: Could not load credentials from any providers . Did you figure it out? Thanks.