AWS SDK for Java 2.x에서 특정 자격 증명 공급자 지정 - AWS SDK for Java 2.x

AWS SDK for Java 2.x에서 특정 자격 증명 공급자 지정

기본 자격 증명 공급자 체인은 많은 시나리오에서 편리하지만 자격 증명 공급자를 명시적으로 지정하면 인증 동작, 성능 및 보안을 더 잘 제어할 수 있습니다.

자격 증명 공급자를 지정하려는 이유는 다음과 같습니다.

  • 기본 공급자 체인은 여러 소스를 순차적으로 확인하여 지연 시간을 추가할 수 있습니다.

    // The default provider chain checks might check multiple sources until it finds // sufficient configuration. S3Client s3Client = S3Client.builder().build(); // You can specify exactly where to look. S3Client optimizedClient = S3Client.builder() .credentialsProvider(InstanceProfileCredentialsProvider.create()) .build();
  • 자격 증명 구성에 액세스하려면 비표준 위치를 사용해야 합니다.

    // Use configuration from a custom file location. S3Client s3Client = S3Client.builder() .credentialsProvider(ProfileCredentialsProvider.builder() .profileFile(ProfileFile.builder() .content(Paths.get("/custom/path/to/configuration/file")) .type(ProfileFile.Type.CONFIGURATION) // Expects all non-default profiles to be prefixed with "profile". .build()) .profileName("custom") .build()) .build();
  • 다양한 서비스 클라이언트에서 다른 자격 증명을 사용합니다. 예를 들어 애플리케이션이 여러 AWS 계정에 액세스해야 하거나 다른 서비스에 대해 다른 권한을 사용해야 하는 경우:

    // S3 client using one set of credentials. S3Client s3Client = S3Client.builder() .credentialsProvider(ProfileCredentialsProvider.create("s3-readonly")) .build(); // DynamoDB client using different credentials. DynamoDbClient dynamoDbClient = DynamoDbClient.builder() .credentialsProvider(ProfileCredentialsProvider.create("dynamodb-admin")) .build();
  • 자격 증명 새로 고침 동작 제어:

    // Create a provider with custom refresh behavior. StsAssumeRoleCredentialsProvider customRefreshProvider = StsAssumeRoleCredentialsProvider.builder() .refreshRequest(AssumeRoleRequest.builder() .roleArn("arn:aws:iam::123456789012:role/my-role") .roleSessionName("custom-session") .build()) .stsClient(StsClient.create()) .asyncCredentialUpdateEnabled(true) // Use a background thread to prefetch credentials. .build(); S3Client s3Client = S3Client.builder() .credentialsProvider(customRefreshProvider) .build();