Java 从S3读取加密数据
我必须从S3存储桶下载数据,数据经过加密,我有kms密钥来解密数据。代码在EC2实例中运行,EC2实例具有IAM角色以从S3读取。 我在link中看到了一个示例代码,但我无法阅读其中的内容Java 从S3读取加密数据,java,amazon-s3,amazon-ec2,Java,Amazon S3,Amazon Ec2,我必须从S3存储桶下载数据,数据经过加密,我有kms密钥来解密数据。代码在EC2实例中运行,EC2实例具有IAM角色以从S3读取。 我在link中看到了一个示例代码,但我无法阅读其中的内容 Exception in thread "main" com.amazonaws.SdkClientException: Unable to load credentials into profile [default]: AWS Access Key ID is not specified.
Exception in thread "main" com.amazonaws.SdkClientException: Unable to load credentials into profile [default]: AWS Access Key ID is not specified.
at com.amazonaws.auth.profile.internal.ProfileStaticCredentialsProvider.fromStaticCredentials(ProfileStaticCredentialsProvider.java:55)
at com.amazonaws.auth.profile.internal.ProfileStaticCredentialsProvider.<init>(ProfileStaticCredentialsProvider.java:40)
at com.amazonaws.auth.profile.ProfilesConfigFile.fromProfile(ProfilesConfigFile.java:207)
at com.amazonaws.auth.profile.ProfilesConfigFile.getCredentials(ProfilesConfigFile.java:160)
线程“main”com.amazonaws.SdkClientException中的异常:无法将凭据加载到配置文件[默认]:未指定AWS访问密钥ID。
在com.amazonaws.auth.profile.internal.ProfileStaticCredentialsProvider.fromStaticCredentials(ProfileStaticCredentialsProvider.java:55)上
位于com.amazonaws.auth.profile.internal.ProfileStaticCredentialsProvider.(ProfileStaticCredentialsProvider.java:40)
在com.amazonaws.auth.profile.ProfilesConfigFile.fromProfile(ProfilesConfigFile.java:207)上
在com.amazonaws.auth.profile.ProfilesConfigFile.getCredentials上(ProfilesConfigFile.java:160)
有人能告诉我哪里出了问题,或者给出一些关于如何在没有凭据的情况下从S3存储桶读取加密数据的指导方针吗?我通过提供InstanceProfileCredentialsProvider找到了一个解决方案。下面是代码
String kms_key = Constants.KMS_key;
String inputString = null;
KMSEncryptionMaterialsProvider materialProvider = new KMSEncryptionMaterialsProvider(kms_key);
AmazonS3EncryptionClient client = new AmazonS3EncryptionClient(InstanceProfileCredentialsProvider.getInstance(),
materialProvider);
S3Object downloadedObject = client.getObject(bucketName, filePath);
if (null != downloadedObject) {
inputString = convertToString(downloadedObject.getObjectContent());
}
我通过提供InstanceProfileCredentialsProvider找到了一个解决方案
String kms_key = Constants.KMS_key;
String inputString = null;
KMSEncryptionMaterialsProvider materialProvider = new KMSEncryptionMaterialsProvider(kms_key);
AmazonS3EncryptionClient client = new AmazonS3EncryptionClient(InstanceProfileCredentialsProvider.getInstance(),
materialProvider);
S3Object downloadedObject = client.getObject(bucketName, filePath);
if (null != downloadedObject) {
inputString = convertToString(downloadedObject.getObjectContent());
}