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

Cannot read property 'byteLength' of undefined #2437

Closed
ghost opened this issue May 27, 2021 · 7 comments
Closed

Cannot read property 'byteLength' of undefined #2437

ghost opened this issue May 27, 2021 · 7 comments
Labels
bug This issue is a bug. closed-for-staleness response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.

Comments

@ghost
Copy link

ghost commented May 27, 2021

Describe the bug

  • Authenticated primary account using @aws-sdk/credential-provider-sso
  • Leveraged STSClient and AssumeRoleCommand to assume role with SSO Creds to another AWS Account
  • Leveraged STS Credentials to Open a Connection to S3Client and ListBucketsCommand
  • Bug is apparent utilising the above method and repeatable

Your environment

SDK version number

"@aws-sdk/client-s3": "^3.17.0",
"@aws-sdk/client-sts": "^3.17.0",
"@aws-sdk/credential-provider-sso": "^3.17.0",

Is the issue in the browser/Node.js/ReactNative?

Node.JS

Details of the browser/Node.js/ReactNative version

v14.16.1

Steps to reproduce

const { fromSSO } = require("@aws-sdk/credential-provider-sso");
const { S3Client, ListBucketsCommand } = require("@aws-sdk/client-s3");
const { STSClient, AssumeRoleCommand } = require("@aws-sdk/client-sts");

const awsProfile = "default";
const awsRegion = "ap-southeast-2";
const awsAssumedRole = {
  RoleArn: "arn:aws:iam::x:role/x",
  RoleSessionName: "currentSession",
};

// Use AWS CLI SSO to create default authentication
const connectionConfig = {
  credentials: fromSSO({ profile: awsProfile }),
  region: awsRegion,
};

// Using SSO Credentials assume a role to a customers environment
const stsClient = new STSClient(connectionConfig);
const stsCommand = new AssumeRoleCommand(awsAssumedRole);

// Query STS to Assume role and generate credentials
stsClient
  .send(stsCommand)
  .then((stsData) => {
    // This method where change the object's keys to lowercase works
    // let currentCredentials = {
    //   credentials: {
    //     accessKeyId: stsData.Credentials.AccessKeyId,
    //     secretAccessKey: stsData.Credentials.SecretAccessKey,
    //     sessionToken: stsData.Credentials.SessionToken,
    //   },
    //   region: awsRegion,
    // };

    // This method always fails with error:
    // TypeError: Cannot read property 'byteLength' of undefined
    let currentCredentials = {
      credentials: stsData.Credentials,
      region: awsRegion,
    };

    // Create connection to S3
    let s3Command = new ListBucketsCommand({});
    let s3Client = new S3Client(currentCredentials);

    // Query Buckets using S3 Config
    s3Client
      .send(s3Command)
      .then((s3Data) => {
        console.log(s3Data.Buckets);
      })
      .catch((err) => {
        console.error(err);
      });
  })
  .catch((err) => {
    console.error(err);
  });

Observed behavior

Fails to login and provides error described in title see extended error below

Expected behavior

Login as intended without have to recreate the object with different key spelling

Additional context

TypeError: Cannot read property 'byteLength' of undefined
    at Object.fromArrayBuffer (C:\Users\benja\code\wip-js\patching-automation\node_modules\@aws-sdk\util-buffer-from\dist\cjs\index.js:6:60)
    at castSourceData (C:\Users\benja\code\wip-js\patching-automation\node_modules\@aws-sdk\hash-node\dist\cjs\index.js:29:31)
    at Hash.update (C:\Users\benja\code\wip-js\patching-automation\node_modules\@aws-sdk\hash-node\dist\cjs\index.js:12:26)
    at hmac (C:\Users\benja\code\wip-js\patching-automation\node_modules\@aws-sdk\signature-v4\dist\cjs\credentialDerivation.js:60:10)
    at Object.getSigningKey (C:\Users\benja\code\wip-js\patching-automation\node_modules\@aws-sdk\signature-v4\dist\cjs\credentialDerivation.js:32:29)
    at SignatureV4.getSigningKey (C:\Users\benja\code\wip-js\patching-automation\node_modules\@aws-sdk\signature-v4\dist\cjs\SignatureV4.js:139:39)
    at SignatureV4.signRequest (C:\Users\benja\code\wip-js\patching-automation\node_modules\@aws-sdk\signature-v4\dist\cjs\SignatureV4.js:98:73)
    at async C:\Users\benja\code\wip-js\patching-automation\node_modules\@aws-sdk\middleware-signing\dist\cjs\middleware.js:14:22
    at async StandardRetryStrategy.retry (C:\Users\benja\code\wip-js\patching-automation\node_modules\@aws-sdk\middleware-retry\dist\cjs\defaultStrategy.js:56:46)
    at async C:\Users\benja\code\wip-js\patching-automation\node_modules\@aws-sdk\middleware-logger\dist\cjs\loggerMiddleware.js:6:22 {
  '$metadata': { attempts: 1, totalRetryDelay: 0 }
}
@ghost ghost added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 27, 2021
@ernestofgonzalez
Copy link

I'm facing the same issue with "@aws-sdk/client-elastic-transcoder": "^3.17.0".

const client: ElasticTranscoderClient =
  new ElasticTranscoderClient<ElasticTranscoderClientConfig>({
    credentials: {
      AccessKeyId: AWS_ACCESS_KEY_ID,
      SecretAccessKey: AWS_SECRET_ACCESS_KEY,
    },
    region: AWS_STORAGE_MEDIA_INPUT_BUCKET_REGION,
  });

const command: CreateJobCommand =
  new CreateJobCommand<CreateJobCommandInput>({
    PipelineId: AWS_ELASTIC_TRANSCODER_PIPELINE_ID,
    Inputs: [
      {
        Key: INPUT_KEY,
      },
    ],
    Outputs: [
      {
        Key: INPUT_KEY + "/hls_1000k_",
        PresetId: "1351620000001-200030",
        SegmentDuration: "1",
        ThumbnailPattern: "{resolution}_{count}",
      },
    ],
  });

try {
  const data = await client.send(command);
} catch (error) {
 console.error(error)
} finally {
  // finally.
}

which returns

ERROR [TypeError: undefined is not an object (evaluating 'data.byteLength')]

Any idea on what it might be?

@ernestofgonzalez
Copy link

I'll go ahead and create a repo to reproduce this.

@ernestofgonzalez
Copy link

Here is a minimal repo.

@ajredniwja
Copy link
Member

Hi @ernestofgonzalez, thanks for opening this issue, can you check if you get the same error with the latest version of the SDK?

I used the code:

import { ElasticTranscoderClient, CreateJobCommand } from "@aws-sdk/client-elastic-transcoder";


(async ()=> {
    const client: ElasticTranscoderClient =
    new ElasticTranscoderClient({
      region: "us-west-2",
    });
  
  const command: CreateJobCommand =
  new CreateJobCommand({
      PipelineId: "id-123",
      Inputs: [
        {
          Key: 	
          "video-to-pipe.mp4",
        },
      ],
      Outputs: [
        {
          Key: "key" + '/hls_1000k_',
          PresetId: '1351620000001-200030',
          SegmentDuration: '1',
          ThumbnailPattern: '{resolution}_{count}',
        },
      ],
    });
  
  try {
    const data = await client.send(command);

    console.log(data)
  } catch (error) {
   console.log(error)
  } finally {
    // finally.
  }
})();

And I get httpStatusCode: 201
@aws-sdk/client-elastic-transcoder@3.22.0

@ajredniwja ajredniwja added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Jul 21, 2021
@ernestofgonzalez
Copy link

Hi @ernestofgonzalez, thanks for opening this issue, can you check if you get the same error with the latest version of the SDK?

I used the code:

import { ElasticTranscoderClient, CreateJobCommand } from "@aws-sdk/client-elastic-transcoder";


(async ()=> {
    const client: ElasticTranscoderClient =
    new ElasticTranscoderClient({
      region: "us-west-2",
    });
  
  const command: CreateJobCommand =
  new CreateJobCommand({
      PipelineId: "id-123",
      Inputs: [
        {
          Key: 	
          "video-to-pipe.mp4",
        },
      ],
      Outputs: [
        {
          Key: "key" + '/hls_1000k_',
          PresetId: '1351620000001-200030',
          SegmentDuration: '1',
          ThumbnailPattern: '{resolution}_{count}',
        },
      ],
    });
  
  try {
    const data = await client.send(command);

    console.log(data)
  } catch (error) {
   console.log(error)
  } finally {
    // finally.
  }
})();

And I get httpStatusCode: 201
@aws-sdk/client-elastic-transcoder@3.22.0

Hi @ajredniwja. Thanks for answering.

Eventually I fixed it. I think it occurs when you don't have the required permissions to do the action you're requesting.
In my case, the user whose credentials I was using did not have all the Elastic Transcoder and S3 permissions necessary. As soon as I fixed this, all worked correctly.

I can't today, but I'll test it with @aws-sdk/client-elastic-transcoder@3.22.0 and a user without the necessary permissions and see if I get the same error. I'll get back to you.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Jul 23, 2021
@ajredniwja ajredniwja added the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Sep 17, 2021
@github-actions
Copy link

This issue has not received a response in 1 week. If you still think there is a problem, please leave a comment to avoid the issue from automatically closing.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Sep 18, 2021
@github-actions
Copy link

github-actions bot commented Oct 6, 2021

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. closed-for-staleness response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants