凭证提供程序更改 - AWS SDK for Java 2.x

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

凭证提供程序更改

本部分提供了AWS SDK for Java 1.x 与 2.x 版之间的凭证提供程序类和方法名称更改的映射。

显著差异

  • 在版本 2.x 中,默认凭证提供程序会在加载环境变量之前先加载系统属性。有关更多信息,请参阅使用凭证

  • 构造函数方法已被替换为 createbuilder 方法。

    DefaultCredentialsProvider.create();
  • 默认情况下,不再设置异步刷新。您必须使用凭证提供程序的 builder 指定它。

    ContainerCredentialsProvider provider = ContainerCredentialsProvider.builder() .asyncCredentialUpdateEnabled(true) .build();
  • 您可以使用 ProfileCredentialsProvider.builder() 指定自定义配置文件的路径。

    ProfileCredentialsProvider profile = ProfileCredentialsProvider.builder() .profileFile(ProfileFile.builder().content(Paths.get("myProfileFile.file")).build()) .build();
  • 配置文件格式已更改,以更贴近于 AWS CLI。有关详细信息,请参阅《AWS Command Line Interface 用户指南》中的配置 AWS CLI

版本 1.x 与 2.x 之间的凭证提供程序更改映射

AWSCredentialsProvider

更改类别 1.x 2.x
软件包/类名 com.amazonaws.auth.AWSCredentialsProvider software.amazon.awssdk.auth.credentials.AwsCredentialsProvider
方法名 getCredentials resolveCredentials
不支持的方法 refresh 不支持

DefaultAWSCredentialsProviderChain

更改类别 1.x 2.x
软件包/类名 com.amazonaws.auth.DefaultAWSCredentialsProviderChain software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider
创建 new DefaultAWSCredentialsProviderChain DefaultCredentialsProvider.create
不支持的方法 getInstance 不支持
外部设置的优先顺序

系统属性之前的环境变量

环境变量之前的系统属性

AWSStaticCredentialsProvider

更改类别 1.x 2.x
软件包/类名 com.amazonaws.auth.AWSStaticCredentialsProvider software.amazon.awssdk.auth.credentials.StaticCredentialsProvider
创建 new AWSStaticCredentialsProvider StaticCredentialsProvider.create

EnvironmentVariableCredentialsProvider

更改类别 1.x 2.x
软件包/类名 com.amazonaws.auth.EnvironmentVariableCredentialsProvider software.amazon.awssdk.auth.credentials.EnvironmentVariableCredentialsProvider
创建 new EnvironmentVariableCredentialsProvider EnvironmentVariableCredentialsProvider.create
环境变量名 AWS_ACCESS_KEY AWS_ACCESS_KEY_ID
AWS_SECRET_KEY AWS_SECRET_ACCESS_KEY

SystemPropertiesCredentialsProvider

更改类别 1.x 2.x
软件包/类名 com.amazonaws.auth.SystemPropertiesCredentialsProvider software.amazon.awssdk.auth.credentials.SystemPropertyCredentialsProvider
创建 new SystemPropertiesCredentialsProvider SystemPropertiesCredentialsProvider.create
系统属性名称 aws.secretKey aws.secretAccessKey

ProfileCredentialsProvider

更改类别 1.x 2.x
软件包/类名 com.amazonaws.auth.profile.ProfileCredentialsProvider software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider
创建 new ProfileCredentialsProvider ProfileCredentialsProvider.create
自定义配置文件的位置
  • AWS_CREDENTIAL_PROFILES_FILE 环境变量

  • new ProfileCredentialsProvider

  • AWS_SHARED_CREDENTIALS_FILE 环境变量

  • ProfileCredentialsProvider.builder

ContainerCredentialsProvider

更改类别 1.x 2.x
软件包/类名 com.amazonaws.auth.ContainerCredentialsProvider software.amazon.awssdk.auth.credentials.ContainerCredentialsProvider
创建 new ContainerCredentialsProvider ContainerCredentialsProvider.create
指定异步刷新 不支持 默认行为

InstanceProfileCredentialsProvider

更改类别 1.x 2.x
软件包/类名 com.amazonaws.auth.InstanceProfileCredentialsProvider software.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider
创建 new InstanceProfileCredentialsProvider InstanceProfileCredentialsProvider.create
指定异步刷新 new InstanceProfileCredentialsProvider(true)

InstanceProfilerCredentialProvider.builder().asyncCredentialUpdateEnabled(true).build()

系统属性名称 com.amazonaws.sdk.disableEc2Metadata aws.disableEc2Metadata
com.amazonaws.sdk.ec2MetadataServiceEndpointOverride aws.ec2MetadataServiceEndpoint

STSAssumeRoleSessionCredentialsProvider

更改类别 1.x 2.x
软件包/类名 com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider
创建
  • new STSAssumeRoleSessionCredentialsProvider

  • new STSAssumeRoleSessionCredentialsProvider.Builder

StsAssumeRoleCredentialsProvider.builder
异步刷新 默认行为 默认行为
配置 new STSAssumeRoleSessionCredentialsProvider.Builder 配置StsClientAssumeRoleRequest请求

STSSessionCredentialsProvider

更改类别 1.x 2.x
软件包/类名 com.amazonaws.auth.STSSessionCredentialsProvider software.amazon.awssdk.services.sts.auth.StsGetSessionTokenCredentialsProvider
创建

new STSAssumeRoleSessionCredentialsProvider

StsGetSessionTokenCredentialsProvider.builder
异步刷新 默认行为 StsGetSessionTokenCredentialsProvider.builder
配置 构造器参数 在生成器中配置 an StsClient d GetSessionTokenRequest 请求

WebIdentityFederationSessionCredentialsProvider

更改类别 1.x 2.x
软件包/类名 com.amazonaws.auth.WebIdentityFederationSessionCredentialsProvider software.amazon.awssdk.services.sts.auth.StsAssumeRoleWithWebIdentityCredentialsProviderr
创建

new WebIdentityFederationSessionCredentialsProvider

StsAssumeRoleWithWebIdentityCredentialsProvider.builder
异步刷新 默认行为 StsAssumeRoleWithWebIdentityCredentialsProvider.builder
配置 构造器参数 在生成器中配置 an StsClient d AssumeRoleWithWebIdentityRequest 请求

类被替换

1.x 级 2.x 替换类
com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper software.amazon.awssdk.auth.credentials.ContainerCredentialsProvidersoftware.amazon.awssdk.auth.credentials.InstanceProfileCredentialsProvider
com.amazonaws.services.s3.S3CredentialsProviderChain software.amazon.awssdk.auth.credentials.DefaultCredentialsProvidersoftware.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider

类已删除

1.x 级
com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider
com.amazonaws.auth.PropertiesFileCredentialsProvider