Navigation Menu

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

sts.assumeRole().promise() returns undefined when succeds #2015

Closed
mim-Armand opened this issue Apr 18, 2018 · 10 comments
Closed

sts.assumeRole().promise() returns undefined when succeds #2015

mim-Armand opened this issue Apr 18, 2018 · 10 comments
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made. guidance Question that needs advice or information.

Comments

@mim-Armand
Copy link

Using callback works in both happy-path and failure:

// This works
assumeRole() {
    let params = {
        RoleArn: 'arn:aws:iam::xxxxxx:role/test_assume_role',
        RoleSessionName: 'Bob',
    };
    return sts.assumeRole(params, function(err, data) {
        if (err) console.log(err, err.stack); // an error occurred
        else     console.log(data);           // successful response
    });
  }

using .promise() however returns undefined when the request succeeds, it behaves as expected when the request fails:

// This returns undefined for happy-path
assumeRole() {
    let params = {
        RoleArn: 'arn:aws:iam::xxxxxx:role/test_assume_role',
        RoleSessionName: 'Bob',
    };
    
    return sts.assumeRole(params)
      .promise()
      .then((data) => {
        console.log('ASSUME ROLE RESULTS >>> ', data);
      })
        .catch( (err) => {
          console.log('ERROR ASSUMING ROLE: ', err);
        });
  }

Thanks

@AllanZhengYP
Copy link
Contributor

Hi @mim-Armand, I cannot reproduce this issue. Are you using any un-default promise library?

@mim-Armand
Copy link
Author

Not using any library for that, I simply add ( the undocumented ) .promise() at the end of the method call, as it does promisify most of the other methods I've worked with, it does with this one too, the only difference is that it returns undefined when the promise is resolved.

So sts.assumeRole(params).promise() returns the correct response for you? If so, please let me know and I'll do more investigation to find out what was the cause of the issue. thanks

@AllanZhengYP
Copy link
Contributor

Yes. I used the code snippet you shared as above and it works as expected. I was using a test user with all STS permissions. Can you show me what's the printout you get from the code snippet above?

@mim-Armand
Copy link
Author

the printout was undefined when stringified, but I think found the problem, adding .promise() doesn't return a normal promise, in contrary to the promises standard api which can have more than one .then() and executes them one after the other, AWS Node SDK, executes the second then() as well but it doesn't pass the resolved value to thens after the first one.
I had one then() in my class and one in my test, I was logging the results in my test which was printing undefined. however, logging the results in the class itself works, and if I remove the then() from the class, the test will start working.
So I will close this issue as it's kind of solved, I appreciate your help @AllanFly120

@srchase srchase added guidance Question that needs advice or information. and removed Question labels Jan 4, 2019
@realtaraharris
Copy link

realtaraharris commented Jun 12, 2019

I have run into this same issue, and the discussion above is about as clear as mud. Is there an actual code example demonstrating how to work around this issue?

I can't just use the v3 SDK because it won't be out for at least another six months...

@mim-Armand
Copy link
Author

@maxharris9 The snippet in the original post actually works, just make sure to consume the promise only in one place otherwise it may cause a racing condition.

There is a difference ( or maybe a bug ) in the implementation of the Promise in this SDK ( at least the version I was using back then ) and the standard implementation/specifications of the Promise APIs:
In the standard spec, when a promise is resolved/rejected, all the subscribers will be notified ( This is called Promise Branching ), but here only one of them will receive the results ( that's not the case however when the promise is rejected, pointing to a possible bug, again )

I will re-open this issue hoping someone will explain it better and/or clearer than me to help you out, or put it on the roadmap if it's a bug or something that can help more people, but otherwise please feel free to close it

@mim-Armand mim-Armand reopened this Jun 12, 2019
@realtaraharris
Copy link

Dear Amazon: await sts.assumeRole(params).promise() doesn't work, and it should

@AllanZhengYP
Copy link
Contributor

AllanZhengYP commented Aug 29, 2019

@maxharris9 Can you make sure the 'complete' event is triggered in your request? like here:

request.
  on('complete', function(resp) {
    console.log('request completes: ', resp.data);
  });
await request.promise();

More information about event listeners: https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/using-a-response-event-handler.html

@ajredniwja ajredniwja added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Nov 5, 2019
@no-response
Copy link

no-response bot commented Nov 12, 2019

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@no-response no-response bot closed this as completed Nov 12, 2019
@lock
Copy link

lock bot commented Nov 19, 2019

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.

@lock lock bot locked as resolved and limited conversation to collaborators Nov 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
closing-soon This issue will automatically close in 4 days unless further comments are made. guidance Question that needs advice or information.
Projects
None yet
Development

No branches or pull requests

5 participants