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.

Mismatch Credential Type (@aws-sdk/client-ec2 and @aws-sdk/client-sts)

See original GitHub issue

Describe the bug

Looks like there is a mismatch between credential types in @aws-sdk/client-ec2, @aws-sdk/client-sts such that credentials generated by the Security Token Service SDK can’t directly be used in the EC2 SDK.

Type defintion of Credentials from @aws-sdk/client-ec2

interface Credentials {
    /**
     * AWS access key ID
     */
    readonly accessKeyId: string;
    /**
     * AWS secret access key
     */
    readonly secretAccessKey: string;
    /**
     * A security or session token to use with these credentials. Usually
     * present for temporary credentials.
     */
    readonly sessionToken?: string;
    /**
     * A {Date} when these credentials will no longer be accepted.
     */
    readonly expiration?: Date;
}

Type defintion of Credentials from @aws-sdk/client-sts

interface Credentials {
    /**
     * <p>The access key ID that identifies the temporary security credentials.</p>
     */
    AccessKeyId: string | undefined;
    /**
     * <p>The secret access key that can be used to sign requests.</p>
     */
    SecretAccessKey: string | undefined;
    /**
     * <p>The token that users must pass to the service API to use the temporary
     *          credentials.</p>
     */
    SessionToken: string | undefined;
    /**
     * <p>The date on which the current credentials expire.</p>
     */
    Expiration: Date | undefined;
}

Your environment

SDK version number

@aws-sdk/client-ec2@3.12.0 @aws-sdk/client-sts@3.13.0

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

Node.js

Details of the browser/Node.js/ReactNative version

v15.10.0

Steps to reproduce

const credentialsProvider = fromIni({ profile: argv.profile });

const roleCredentialsProvider = async () => {
  const client = new STSClient({ region: 'us-east-1', credentials: credentialsProvider});

  const assumeRoleRequest = new AssumeRoleCommand({
    RoleArn: 'arn:aws:iam::<ACCOUNT_HERE>:role/<ROLE_HERE>',
    RoleSessionName: '<SESSION_NAME>',
  });

  const response = await client.send(assumeRoleRequest);

  return response.Credentials;
};

const client = new EC2Client({ region: 'us-east-1', credentials: roleCredentialsProvider });

Observed behavior

The error that results in this incorrect value being passed in.

TypeError: Cannot read property 'byteLength' of undefined
    at Object.fromArrayBuffer (/Users/tcvs/Development/Tulip/tulip/environments/node_modules/@aws-sdk/util-buffer-from/dist/cjs/index.js:6:60)
    at castSourceData (/Users/tcvs/Development/Tulip/tulip/environments/node_modules/@aws-sdk/hash-node/dist/cjs/index.js:29:31)
    at Hash.update (/Users/tcvs/Development/Tulip/tulip/environments/node_modules/@aws-sdk/hash-node/dist/cjs/index.js:12:26)
    at hmac (/Users/tcvs/Development/Tulip/tulip/environments/node_modules/@aws-sdk/signature-v4/dist/cjs/credentialDerivation.js:60:10)
    at Object.getSigningKey (/Users/tcvs/Development/Tulip/tulip/environments/node_modules/@aws-sdk/signature-v4/dist/cjs/credentialDerivation.js:32:29)
    at SignatureV4.getSigningKey (/Users/tcvs/Development/Tulip/tulip/environments/node_modules/@aws-sdk/signature-v4/dist/cjs/SignatureV4.js:139:39)
    at SignatureV4.signRequest (/Users/tcvs/Development/Tulip/tulip/environments/node_modules/@aws-sdk/signature-v4/dist/cjs/SignatureV4.js:98:73)
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
    at async /Users/tcvs/Development/Tulip/tulip/environments/node_modules/@aws-sdk/middleware-signing/dist/cjs/middleware.js:14:22
    at async StandardRetryStrategy.retry (/Users/tcvs/Development/Tulip/tulip/environments/node_modules/@aws-sdk/middleware-retry/dist/cjs/defaultStrategy.js:56:46)
    at async /Users/tcvs/Development/Tulip/tulip/environments/node_modules/@aws-sdk/middleware-logger/dist/cjs/loggerMiddleware.js:6:22
    at async initSpotInstances (/Users/tcvs/Development/Tulip/tulip/environments/cypress/loadTest/ec2LoadTest.js:171:30)
    at async main (/Users/tcvs/Development/Tulip/tulip/environments/cypress/loadTest/ec2LoadTest.js:255:18) {
  '$metadata': { attempts: 1, totalRetryDelay: 0 }
}

Expected behaviour

Expected that I would be able to pass the credentials object directly or at least have a more usuable error to make this more easily debuggable.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
jackallnuttcommented, Apr 21, 2021

I am experiencing the same problem with @aws-skd/client-s3.

0reactions
github-actions[bot]commented, Jul 1, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS SDK for JavaScript v3
The AWS SDK for JavaScript v3 is a rewrite of v2 with some great new features. As with version 2, it enables you...
Read more >
AssumeRoleCommand | EC2 Instance Connect Client
Returns a set of temporary security credentials that you can use to access Amazon Web Services resources that you might not normally have...
Read more >
How we halved the publish size of modular AWS SDK for ...
The client-sts is of size 1.4 MB and contains 115 files with 10054 lines of code. $ npm install @aws-sdk/client-sts@3.33.0 --save-exact ..
Read more >
Working with AWS Credentials - AWS SDK for Java 1.x
How to load credentials for AWS using the AWS SDK for Java. ... that is different from the default credential provider chain by...
Read more >
EC2 Client - AWS SDK for JavaScript v3
Installing. To install the this package, simply type add or install @aws-sdk/client-ec2 using your favorite package manager:.
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