I have to generate read only and write only tokens for a file in S3.
What I have tried so far:
What this does is
Create STS client
AWSSecurityTokenServiceClient sts_client = (AWSSecurityTokenServiceClient) AWSSecurityTokenServiceClientBuilder.standard()
.withRegion(Regions.DEFAULT_REGION).build();
Create assume role request
AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest()
.withRoleArn("arn:aws:iam::123456789123:role/iam-role-name")
.withDurationSeconds(7200)
.withRoleSessionName("session-role-"+System.currentTimeMillis());
Generate token request
GetSessionTokenRequest session_token_request = new GetSessionTokenRequest();
Generate tokens
GetSessionTokenResult session_token_result = sts_client.getSessionToken(session_token_request);
Create credentials
Credentials session_creds = session_token_result.getCredentials();
Create basic credentials
BasicSessionCredentials sessionCredentials = new BasicSessionCredentials(
session_creds.getAccessKeyId(),
session_creds.getSecretAccessKey(),
session_creds.getSessionToken());
expectation
I found a solutions to this .
what is does is :