我试图通过附加文件,在同一个密钥下将多个文件上传到Amazon S3.我有一个文件名列表,并希望按该顺序上传/追加文件.我几乎完全遵循本教程,但我首先循环遍历每个文件并部分上传.因为文件在hdfs上(Path实际上是org.apache.hadoop.fs.Path),所以我使用输入流来发送文件数据.下面是一些伪代码(我正在评论教程中逐字逐句的块):
// Create a list of UploadPartResponse objects. You get one of these for
// each part upload.
List<PartETag> partETags = new ArrayList<PartETag>();
// Step 1: Initialize.
InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest(
bk.getBucket(), bk.getKey());
InitiateMultipartUploadResult initResponse =
s3Client.initiateMultipartUpload(initRequest);
try {
int i = 1; // part number
for (String file : files) {
Path filePath = new Path(file);
// Get the input stream and content length
long contentLength = fss.get(branch).getFileStatus(filePath).getLen();
InputStream is = fss.get(branch).open(filePath);
long filePosition = …Run Code Online (Sandbox Code Playgroud) 我的目标是从 S3 获取一个对象(图像),更改文件的元数据,并将其替换为已更改元数据的新文件。
为了更改元数据,我使用的是commons 图像库。我对下面的示例进行了编码,该示例按预期工作,但不处理 S3。
File newFile = new File("newImage2.jpg");
OutputStream os = new BufferedOutputStream(new FileOutputStream(newFile))
InputStream isNew = new BufferedInputStream(new FileInputStream(newFile))
InputStream is = new BufferedInputStream(new FileInputStream(new File("newImage.jpg")))
try {
String xmpXml = "<x:xmpmeta>" +
"\n<Lifeshare>" +
"\n\t<Date>"+"some date"+"</Date>" +
"\n\t<Latitude>"+"somelat"+"</Latitude>" +
"\n\t<Longitude>"+"somelong"+"</Longitude>" +
"\n\t<Altitude>"+"somealt"+"</Altitude>" +
"\n\t<Z>"+"someZ"+"</Z>" +
"\n\t<X>"+"someX"+"</X>" +
"\n\t<Y>"+"Some y"+"</Y>" +
"\n</Lifeshare>" +
"\n</x:xmpmeta>";
JpegXmpRewriter rewriter = new JpegXmpRewriter();
rewriter.updateXmpXml(is,os, xmpXml);
String newXmpXml = Imaging.getXmpXml(isNew, "newImage2.jpg");
println newXmpXml
}
finally {
is.close()
os.close()
} …Run Code Online (Sandbox Code Playgroud) java image-processing amazon-s3 aws-java-sdk apache-commons-imaging
我们正在运行一个基于Spring的项目,其中Cognito作为标识服务。
我们有一个项目要求,为Cognito用户池中的用户自定义验证电子邮件和邀请电子邮件。(请参阅here for the AWS doc)
默认验证消息:
您的验证码为{####}。
默认邀请消息:
您的用户名是{username},临时密码是{####}。
我们希望包括email,phone_number和name用户属性为这些电子邮件。是否有可能做到这一点?我搜索文档无济于事-确实需要一些建议。
spring amazon-web-services spring-boot aws-java-sdk aws-cognito
我有一个 900 MB 的文件,如果尚未下载到位,我想将其从 S3 下载到磁盘。如果文件尚未就位,是否有一种简单的方法可以让我仅下载文件?我知道 S3 支持查询文件的 MD5 校验和,但我希望不必自己构建这个逻辑。
我正在尝试s3 sdk进行非常基本的测试并得到以下错误.
引起:java.lang.NoSuchFieldError:SIGNING_REGION at com.amazonaws.services.s3.AmazonS3Client.createRequest(AmazonS3Client.java:4227)at com.amazonaws.services.s3.AmazonS3Client.createRequest(AmazonS3Client.java:4203)at com .amazonaws.services.s3.AmazonS3Client.listBuckets(AmazonS3Client.java:929)at com.amazonaws.services.s3.AmazonS3Client.listBuckets(AmazonS3Client.java:936)
AWS-Java的SDK-S3
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.288</version>
</dependency
ClientConfiguration cf = new ClientConfiguration();
AWSCredentials credentials = new BasicAWSCredentials("<id>","<secret>");
AmazonS3 amazonS3Client=
AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials)).withRegion(Regions.US_EAST_1).build();
List<Bucket> buckets = amazonS3Client.listBuckets();
Run Code Online (Sandbox Code Playgroud)
Maven依赖树:
O] --- maven-dependency-plugin:2.10:tree (default-cli) @ AwsSdkDemo ---
O] com.example:AwsSdkDemo:jar:0.0.1-SNAPSHOT
O] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.5.10.RELEASE:compile
O] | +- org.springframework.boot:spring-boot-starter:jar:1.5.10.RELEASE:compile
O] | | +- org.springframework.boot:spring-boot:jar:1.5.10.RELEASE:compile
O] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.10.RELEASE:compile
O] | | +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.10.RELEASE:compile
O] | | | +- ch.qos.logback:logback-classic:jar:1.1.11:compile
O] | | | | \- ch.qos.logback:logback-core:jar:1.1.11:compile
O] | …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用aws-sdk-java AwsS3client与minio存储进行通信.从CLI我可以做到:
aws --profile=minioplay --endpoint-url https://play.minio.io:9000 s3 cp logback.xml s3://miniohstest-jixusroqeb --debug
Run Code Online (Sandbox Code Playgroud)
因此使用非默认配置文件和自定义端点.不知道如何从java sdk执行此操作(我能够吗?).我粗略地将上面的awscli命令翻译成这个scala片段:
val cred = ...
val endpoint = "https://play.minio.io:9000"
val client = AmazonS3ClientBuilder
.standard()
.withCredentials(cred)
.withEndpointConfiguration(
new EndpointConfiguration(
endpoint,
AwsHostNameUtils.parseRegion(endpoint, AmazonS3Client.S3_SERVICE_NAME)
)
)
.build()
Run Code Online (Sandbox Code Playgroud)
使用上面的客户端我只能做出非常简单的请求,例如:
client.listBuckets().asScala.foreach(println(_))
Run Code Online (Sandbox Code Playgroud)
哪个有效.但是当我尝试做一些先进的事情时,例如:
val listRequest = new ListObjectsRequest()
.withBucketName("miniohstest-jixusroqeb")
//.withPrefix(r.getURI.getPath)
//.withDelimiter(delimiter)
val res = client.listObjects(listRequest)
res.getObjectSummaries.forEach(x => println(x.getKey))
Run Code Online (Sandbox Code Playgroud)
它抛出以下异常:
Exception in thread "main" com.amazonaws.SdkClientException: Unable to execute HTTP request: miniohstest-jixusroqeb.play.minio.io
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleRetryableException(AmazonHttpClient.java:1114)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1064)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:743)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我要使用ContainerCredentialsProvider(CredentialsEndpointProvider)
代替ContainerCredentialsProvider(),因为后者已弃用。
目前,我正在使用以下弃用的构造函数ContainerCredentialsProvider():
AWSSimpleSystemsManagement ssm =
AWSSimpleSystemsManagementClientBuilder
.standard()
.withRegion(region)
.withCredentials(new ContainerCredentialsProvider())
.build();
Run Code Online (Sandbox Code Playgroud)
CredentialsEndpointProvider是一个抽象类。我需要ECSCredentialsEndPointProvider在docker中使用类似的内容,但我不确定该怎么做。任何帮助表示赞赏。
当我创建一个新队列并将其订阅到 Java 主题时,没有消息出现。同样通过 AWS Web 控制台工作正常。
我想我必须以某种方式确认订阅,但该sns.confirmSubscription方法需要一个令牌 - 我从哪里得到它?
这是我的Java代码:
String queueURL = sqs.createQueue("my-queue").getQueueUrl();
sns.subscribe(myTopicARN, "sqs", queueURL);
sns.publish(myTopicARN, "{\"payload\":\"test\"}");
sqs.receiveMessage(queueURL).getMessages()
.forEach(System.out::println); // nothing
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
AWS Java SDK ver 1 中的 S3 客户端有一个方法来检查存储桶中对象是否存在
doesObjectExist(bucketName, objectName)
Run Code Online (Sandbox Code Playgroud)
在 SDK 的第 2 版中,我没有看到任何类似的东西,但我想看看我是否遗漏了任何东西。
我唯一的想法是尝试使用
S3Client.getObject(GetObjectRequest)
如果对象不存在,它将抛出 NoSuchKeyExcecption 。我讨厌使用这样的异常。
aws-java-sdk ×10
amazon-s3 ×6
java ×5
aws-sdk ×2
amazon-ecs ×1
aws-cognito ×1
hadoop ×1
spring ×1
spring-boot ×1