无法从链错误中的任何提供商加载 AWS 凭证

Getting Unable to load AWS credentials from any provider in the chain error

我在尝试将文件上传到 AWS Glacier 时遇到以下异常 错误:无法从链中的任何提供商加载 AWS 凭证

我创建了 accessKey 和 SecretKey。 我 运行 的代码与建议的代码相似 这里是:

    public static String vaultName = "myName";
    public static String archiveId = "*** provide archive ID ***";
    public static String archiveToUpload  =  "C:\dev\file.txt";
    

public final static String AWS_DATACENTER_URL = "eu-central-1.amazonaws.com/";
    public final static String GLACIER_URL = "glacier."+AWS_DATACENTER_URL;
    public final static String SQS_URL = "sqs."+AWS_DATACENTER_URL;
    public final static String SNS_URL = "sns."+AWS_DATACENTER_URL;
    public final static String HTTPS_URL = "https://"+GLACIER_URL;
    public final static AWSCredentialsProvider credentials = new ClasspathPropertiesFileCredentialsProvider();
    public static void main(String[] args) {
        
        System.out.println("credentials AKID:" + credentials.getCredentials().getAWSAccessKeyId() + " SK:" + credentials.getCredentials().getAWSSecretKey());
        
        
        AmazonGlacierClient client = new AmazonGlacierClient();
        client.setEndpoint(HTTPS_URL);
        
        ArchiveTransferManager atm = new ArchiveTransferManager(client, credentials);
        try
        {
            archiveId = atm.upload(vaultName, "Tax 2012 documents", new File(archiveToUpload)).getArchiveId();
            System.out.println("uploaded:" + archiveId);
        }
        catch (AmazonClientException
                | FileNotFoundException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

我的凭据文件采用以下格式(凭据对象正在正确读取它):

accessKey=MY_KEY
secretKey=MY_SECRET_KEY

我错过了什么??

由于您使用的是非标准方法来设置凭据,因此您需要将凭据对象传递给客户端,如下所示:

AmazonGlacierClient client = new AmazonGlacierClient(credentials);