Next.js Discord

Discord Forum

"Credential is missing" in NextJS Middleware when using AWS SDK

Unanswered
Cinnamon posted this in #help-forum
Open in Discord
CinnamonOP
Hey all,

I am trying to use the AWS SDK V3 in NextJS middleware.ts to access some DynamoDB table.

import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import {
  DynamoDBDocumentClient,
  GetCommand,
  GetCommandInput,
} from '@aws-sdk/lib-dynamodb';

const client = new DynamoDBClient({});
const docClient = DynamoDBDocumentClient.from(client);

export async function middleware(request: NextRequest) {
  // reading stuff on every request
  const doc = await docClient.send(new GetCommand({ TableName: 'foo', Key: { bar:   'henlo' } }));
  
  // ...
}


Unfortunately, I am always getting following error:

../node_modules/.pnpm/@aws-sdk+client-dynamodb@3.427.0/node_modules/@aws-sdk/client-dynamodb/dist-es/runtimeConfig.browser.js (22:101) @ SignatureV4.eval [as credentialProvider]
 ⨯ Credential is missing


What confuses me is that all AWS environment variables are present and accessible in the middleware and that I do not have this issue in server components and actions.

Is this an issue on my side or is it just not possible to use the AWS SDK in the NextJS middleware (since it's running on edge?)

0 Replies