Search code examples
amazon-web-servicesamazon-s3assume-role

S3-Assume Role from local system


I am trying to run AWS program (https://docs.aws.amazon.com/AmazonS3/latest/dev/AuthUsingTempSessionTokenJava.html)

from my local system to test the assume functionality but I am wondering if I need to configure something else to make it run as I am getting following error on statement 'AssumeRoleResult roleResponse = stsClient.assumeRole(roleRequest);'

: The security token included in the request is invalid. (Service: AWSSecurityTokenService; Status Code: 403; Error Code: InvalidClientTokenId; Request ID: 4ec69431-c382-4cea-8099-b98e77f501ed; Proxy: null)

Solution

  • That call uses V1 to assume a role. Try using the more up to date V2 SDK that you can find here:

    https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/javav2/example_code/sts/src/main/java/com/example/sts/AssumeRole.java

    In fact, it is recommended that you use V2 for S3 operation as well. You can find V2 S3 code examples here:

    https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/javav2/example_code/s3