重新更新临时凭证sts aws

时间:2018-07-09 15:14:38

标签: java amazon-web-services amazon-iam aws-iam

我正在尝试使用AWS中的STS生成临时安全凭证来访问资源。我的尝试是:

AWSSecurityTokenService awsSecurityTokenService = 
AWSSecurityTokenServiceClientBuilder
        .standard().withCredentials(new ProfileCredentialsProvider())
        .withRegion(region).build();
AssumeRoleRequest assumeRoleRequest = new AssumeRoleRequest()
        .withRoleArn(
                "arn:aws:iam::account-id:role/p-27c229ade194_ec2")
        .withRoleSessionName("RedshiftSession");
AssumeRoleResult assumeRoleResult = awsSecurityTokenService
        .assumeRole(assumeRoleRequest);
GetSessionTokenRequest getSessionTokenRequest = new GetSessionTokenRequest();
getSessionTokenRequest.setDurationSeconds(1200);
GetSessionTokenResult getSessionTokenResult = awsSecurityTokenService
        .getSessionToken(getSessionTokenRequest);
Credentials sessionCredentials = getSessionTokenResult.getCredentials();

final String adminAccessKeyId = sessionCredentials.getAccessKeyId();
final String adminAccessSecretKey = sessionCredentials
        .getSecretAccessKey();

但是一旦过期,如何续订此凭证?

0 个答案:

没有答案