AWS 环境变量设置问题
Exception in thread "main" software.amazon.awssdk.core.exception.SdkClientException: Unable to load credentials from any of the providers in the chain AwsCredentialsProviderChain(credentialsProviders=[SystemPropertyCredentialsProvider(), EnvironmentVariableCredentialsProvider(), WebIdentityTokenCredentialsProvider(), ProfileCredentialsProvider(), ContainerCredentialsProvider(), InstanceProfileCredentialsProvider()]) : [SystemPropertyCredentialsProvider(): Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId)., EnvironmentVariableCredentialsProvider(): Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId)., WebIdentityTokenCredentialsProvider(): Either the environment variable AWS_WEB_IDENTITY_TOKEN_FILE or the javaproperty aws.webIdentityTokenFile must be set., ProfileCredentialsProvider(): Profile file contained no credentials for profile 'default': ProfileFile(profiles=[]), ContainerCredentialsProvider(): Cannot fetch credentials from container - neither AWS_CONTAINER_CREDENTIALS_FULL_URI or AWS_CONTAINER_CREDENTIALS_RELATIVE_URI environment variables are set., InstanceProfileCredentialsProvider(): Unable to load credentials from service endpoint.]
方法1:系统属性设置
代码引用:
Region region = Region.CN_NORTHWEST_1;
System.setProperty("aws.accessKeyId",ACCESSKEY);
System.setProperty("aws.secretAccessKey",SecretKey);
Ec2Client ec2 = Ec2Client.builder().region(region).build();
测试验证即可:
describeVolume(ec2);
方法2:被动系统文件(感觉有点被那个啥 ) ~/.aws/credentials
Region region = Region.CN_NORTHWEST_1;
AWSCredentials credentials = new ProfileCredentialsProvider().getCredentials();
Ec2Client ec2 = Ec2Client.builder()
.region(region)
.build();
describeVolume(ec2);
网友评论