java – 无法从类路径中的/AwsCredentials.properties文件加载AWS凭据

使用此代码设置类路径

AWSCredentialsProvider credentialsProvider = new ClasspathPropertiesFileCredentialsProvider();
ec2 = new AmazonEC2Client(credentialsProvider);

以下是AwsCredentials.properties文件的格式

# Fill in your AWS Access Key ID and Secret Access Key
# http://aws.amazon.com/security-credentials
accessKey = keyHere
secretKey = secretKeyHere

下面是我得到的例外

Exception in thread "main" com.amazonaws.AmazonClientException: Unable to load AWS credentials from the /AwsCredentials.properties file on the classpath

    at com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider.getCredentials(ClasspathPropertiesFileCredentialsProvider.java:81)
    at com.amazonaws.services.ec2.AmazonEC2Client.invoke(AmazonEC2Client.java:8359)
最佳答案
您将收到此异常,因为您的AWS SDK无法加载凭据.
您应该做的是转到首选项,然后转到AWS并添加您的密钥和访问密钥.所以你的项目可以检索两个键.

转载注明原文:java – 无法从类路径中的/AwsCredentials.properties文件加载AWS凭据 - 代码日志