AWS Documentation on Java Assuming STS Client not working?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



AWS Documentation on Java Assuming STS Client not working?



As a prereq see this page.



So I can created a small app that is literally a copy-paste of the code they provide. It does run for the given user, I have changed the global variables to the proper values, and I can assume the STS Role that I want via the AWS CLI. However this code will still not assume the proper role.



I export the code as an executable jar, put it up onto my EC2 instance (basic AWS linux instance), and run it. I do have it output the keys from the STS Credentials which are proper and correct, but as soon as it gets down to the S3 client I get access denied (403).



My roles are as follows:



AWS Documentation is hit or miss sometimes, but I can't find anyone else experiencing issues with this code. Like I said if I do the same process of assuming the STS role via CLI, I can do that and it works properly which makes this much more confusing.



Thanks in advance to anyone who can help!





Are your running this code and the CLI from the same machine using the same credentials?
– John Hanley
Aug 11 at 4:35





Yes. The EC2 has no permissions. It has the credentials in it of MyUser, therefore it acts as the user. I run the cli on this instance. I call the assume role CLI command and adjust the environment variables properly. When I try S3 commands they work.
– LindCloud
Aug 11 at 22:45




1 Answer
1



The page you linked has wrong code according to their documentation. The AssumeRole method has different example code is incorrect. There is other documentation that solves the issue see this page. The API documentation example has


AssumeRoleResult response = client.assumeRole(request);



Where the AssumeRole function returns a AssumeRoleResult object, which has different credentials than the credentials that return from the GetSessionTokenRequest class. The Credentials returned are different lengths/sizes and for some reason invalid.



THE FIX:



This code shown on their documentation is invalid.


stsClient.assumeRole(roleRequest);
GetSessionTokenRequest getSessionTokenRequest = new GetSessionTokenRequest();
getSessionTokenRequest.setDurationSeconds(900);
GetSessionTokenResult sessionTokenResult = stsClient.getSessionToken(getSessionTokenRequest);
Credentials sessionCredentials = sessionTokenResult.getCredentials();



The code above should be replaced with the following found here.


AssumeRoleResult response = stsClient.assumeRole(roleRequest);
Credentials sessionCredentials = response.getCredentials();





Yes that worked! Thank you so much!
– LindCloud
Aug 15 at 14:13






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS