尝试使用通过 DefaultCredentialProvider 提供的凭证时,AWS lambda 函数不起作用。
我需要将凭据传递给 S3 才能运行。
代码
def initializeAwsCredentials():AWSCredentials = {
var credentials: AWSCredentials = null
try {
credentials = new ProfileCredentialsProvider().getCredentials
} catch {
case e: Exception => {
throw new AmazonClientException(
"Cannot load the credentials from the credential profiles file. " +
"Please make sure that your credentials file is at the correct " +
"location (~/.aws/credentials), and is in valid format.",
e);
}
}
return credentials
}
def buildS3API(credentials: AWSCredentials): AmazonS3 = {
new AmazonS3Client(credentials) …Run Code Online (Sandbox Code Playgroud)
我是 AWS 新手,
我使用 AWS CLI 在本地配置我的 AWS 凭证,因为我无法将 IAM 角色附加到我的笔记本电脑,
我可以通过 Eclipse IDE 的 AWS 工具包插件看到我的凭证已正确配置。
我提到了这个答案 - AWS S3 upload without access and Secret key in Java,
有人可以帮助我了解如何在代码中设置 S3 存储桶位于哪个区域吗?
或者它是否从 aws configure 命令期间设置的区域中获取区域?
当我尝试使用方法时出现错误s3client.setRegion。
我无法在本地测试此代码,它引发了以下错误 -
com.amazonaws.SdkClientException: Unable to load credentials from service endpoint
Run Code Online (Sandbox Code Playgroud)
以下是我将文件上传到 AWS S3 的代码-
AmazonS3 s3client = AmazonS3ClientBuilder.standard()
.withCredentials(new InstanceProfileCredentialsProvider(false))
.build();
//s3client.setRegion(com.amazonaws.regions.Region.getRegion(Regions.EU_CENTRAL_1));
PutObjectResult result = s3client.putObject(new PutObjectRequest(BUCKET_NAME, BASE_PATH + localFile.getName(), localFile));
Run Code Online (Sandbox Code Playgroud)
完整的错误日志 -
The legacy profile format requires the …Run Code Online (Sandbox Code Playgroud)