美文网首页
aws 对接系统的坎坷

aws 对接系统的坎坷

作者: 猜猜_a873 | 来源:发表于2020-06-10 10:40 被阅读0次

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);

相关文章

网友评论

      本文标题:aws 对接系统的坎坷

      本文链接:https://www.haomeiwen.com/subject/sulgzhtx.html