Предполагаемая роль AWS IAM - PullRequest
0 голосов
/ 20 сентября 2018

Попытка взять на себя роль IAM и получить временные учетные данные для доступа к сервисам AWS.Я настроил роль IAM в AWS и попробовал приведенный ниже код

String clientRegion = "eu-west-1";
    String roleARN = "arn:aws:iam::83883883:role/myrole";
    String roleSessionName = "rolename";


    try {
        // Creating the STS client is part of your trusted code. It has
        // the security credentials you use to obtain temporary security credentials.
        AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard()
                                                .withCredentials(new ProfileCredentialsProvider())
                                                .withRegion(clientRegion)
                                                .build();

        // Assume the IAM role. Note that you cannot assume the role of an AWS root account;
        // Amazon S3 will deny access. You must use credentials for an IAM user or an IAM role.
        AssumeRoleRequest roleRequest = new AssumeRoleRequest()
                                                .withRoleArn(roleARN)
                                                .withRoleSessionName(roleSessionName);
        stsClient.assumeRole(roleRequest);

        // Start a session.
        GetSessionTokenRequest getSessionTokenRequest = new GetSessionTokenRequest();
        // The duration can be set to more than 3600 seconds only if temporary
        // credentials are requested by an IAM user rather than an account owner.
        getSessionTokenRequest.setDurationSeconds(7200);
        GetSessionTokenResult sessionTokenResult = stsClient.getSessionToken(getSessionTokenRequest);
        Credentials sessionCredentials = sessionTokenResult.getCredentials();

        // Package the temporary security credentials as a BasicSessionCredentials object 
        // for an Amazon S3 client object to use.
        BasicSessionCredentials basicSessionCredentials = new BasicSessionCredentials(
                sessionCredentials.getAccessKeyId(), sessionCredentials.getSecretAccessKey(),
                sessionCredentials.getSessionToken());

        System.out.println(basicSessionCredentials);

Но я получаю следующее исключение, у кого-либо есть идеи

10: 38: 50.377 [main] DEBUGcom.amazonaws.metrics.AwsSdkMetrics - Администратор mbean зарегистрирован под com.amazonaws.management:type=AwsSdkMetrics. Исключение в потоке «main» java.lang.NoSuchFieldError: SERVICE_ID на com.amazonaws.services.securitytoen.ken.executeAssumeRole (AWSSecurityTokenServiceClient.java:479) в com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient.assumeRole (AWSSecurityTokenServiceClient.java:460)

...