question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'byteLength' of undefined

See original GitHub issue

I am using Kinesis with v3 nodejs.

Error TypeError: Cannot read property 'byteLength' of undefined at Object.fromArrayBuffer (/Users/mac/www/html/test-api/node_modules/@aws-sdk/util-buffer-from/dist/cjs/index.js:6:60) at Object.toBase64 [as base64Encoder] (/Users/mac/www/html/test-api/node_modules/@aws-sdk/util-base64-node/dist/cjs/index.js:23:31) at serializeAws_json1_1PutRecordsRequestEntry (/Users/mac/www/html/test-api/node_modules/@aws-sdk/client-kinesis/dist/cjs/protocols/Aws_json1_1.js:2626:80) at /Users/onebase/www/html/onebase/quoterules-api/node_modules/@aws-sdk/client-kinesis/dist/cjs/protocols/Aws_json1_1.js:2639:16 at Array.map (<anonymous>)

Code example is throwing above error is as follow : `// Import the required AWS SDK clients and commands for Node.js. const { CognitoIdentityClient } = require(“@aws-sdk/client-cognito-identity”); const { fromCognitoIdentityPool, } = require(“@aws-sdk/credential-provider-cognito-identity”); const { Kinesis, PutRecordsCommand } = require(“@aws-sdk/client-kinesis”);

// Configure Credentials to use Cognito const REGION = “us-east-2”; const client = new Kinesis({ region: REGION, credentials: fromCognitoIdentityPool({ client: new CognitoIdentityClient({ region: REGION }), identityPoolId: “MY SECRET CODE”, // IDENTITY_POOL_ID }), });

var recordData = []; // Create the Amazon Kinesis record. var record = { Data: JSON.stringify({ blog: “Wordpress”, scrollTopPercentage: “25px”, scrollBottomPercentage: “42px”, time: new Date(), }), PartitionKey: “abc”, // Must be a string. }; recordData.push(record); recordData.push(record);

console.log(“recordDatarecordData”, recordData);

const uploadData = async () => { try { const data = await client.send( new PutRecordsCommand({ Records: recordData, StreamName: “visitorDataStream”, }) ); console.log(“data”, data); console.log(“Kinesis updated”, data); } catch (err) { console.log(“Error”, err); } };

uploadData();`

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:7

github_iconTop GitHub Comments

21reactions
ahmedelaminecommented, Dec 27, 2021

Check your credentials in s3Client Try to type the credentials manual without env variables to eliminate confusion, then use the env variables

const s3Client = new S3Client({
  region: REGION,
  credentials: {
    accessKeyId: process.env.ACCESS_KEY,
    secretAccessKey: process.env.SECRET_ACCESS_KEY,
  }
});
10reactions
aldo-rdcommented, Apr 21, 2022

I goten same error when I used Pascal case style in AccessKeyId and SecretAccessKey:

const s3Client = new S3Client({
  region: REGION,
  credentials: {
    AccessKeyId: myAccessKeyId,
    SecretAccessKey: mySecretAccessKey,
  }
});

I changed to Camel style and it works:

const s3Client = new S3Client({
  region: REGION,
  credentials: {
    accessKeyId: myAccessKeyId,
    secretAccessKey: mySecretAccessKey,
  }
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read property 'byteLength' of undefined - AWS S3 ...
I got this error in a React Native app. I was able to fix it by turning off my Dev Tools network inspector....
Read more >
TypeError: Cannot read property 'byteLength' of undefined
Coding example for the question TypeError: Cannot read property 'byteLength' of undefined - AWS S3 Upload-Reactjs.
Read more >
Uncaught (in promise) TypeError: Cannot read properties of ...
bytes() function takes in an arrayBuffer and returns the byteLength . but in this case, the value variable is the buffer. so taking...
Read more >
T284769 TypeError: Cannot read property 'byteLength' of null
Appears to be inside the ogv.js library (not the videojs library, nor the MW payload). Note that this is about the native Uint8Array#byteLength...
Read more >
I keep getting "Cannot read properties of undefined (reading ...
I keep getting "Cannot read properties of undefined (reading 'byteLength')" error when uploading files to a space using aws-sdk for node.js.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found