'Cannot read property 'byteLength' of undefined for aws-sdk js v3 for dynamodb client
I'm trying to connect a nestjs backend (node) with a dynamodb table using @aws-sdk/client-dynamodb but I have a server error:
[Nest] 24019 - 24/08/2021, 21:19:38 ERROR [ExceptionsHandler] Cannot read property 'byteLength' of undefined
TypeError: Cannot read property 'byteLength' of undefined
from
node_modules/@aws-sdk/util-buffer-from/src/index.ts:4:8
I instantiate my client like so:
import { DynamoDB } from "@aws-sdk/client-dynamodb";
// Full DynamoDB Client
const client = new DynamoDB({
region: 'eu-west-2',
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
}
});
I use dotenv to build process env variable
I searched the web, but except for some post saying that I need to lowercase credentials object key which is already done on my code I found nothing
Solution 1:[1]
In order to use .env in NestJS you will need @nestjs/config install it by running npm i @nestjs/config https://docs.nestjs.com/techniques/configuration
@Module({
imports: [
ConfigModule.forRoot()
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule { }
Example of nodejs sdk v3.
const dynamoClient = new DynamoDBClient(
{
region: process.env.DB_REGION,
endpoint: process.env.DB_ENDPOINT,
credentials: {
accessKeyId: process.env.DB_ACCESS_KEY_ID,
secretAccessKey: process.env.DB_SECRET_ACCESS_KEY,
}
}
);
const dbDocumentClient = DynamoDBDocumentClient.from(
dynamoClient
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |