gpt4 book ai didi

lambda 中的 Java AWSClient 引用

转载 作者:行者123 更新时间:2023-12-02 12:06:41 25 4
gpt4 key购买 nike

我正在使用用 java 编写的 lambda 函数来监听 s3 存储桶创建对象requesthandler将调用另一个类“testDownload”来下载对象

当某事发生时AmazonS3 s3 = AmazonS3ClientBuilder.standard().build();已初始化,我在 try catch block 中使用它并检查是否引发异常并且云监视中没有显示错误。你能帮我了解发生了什么吗

public class S3EventProcessor implements RequestHandler<S3Event, String> {
private final org.slf4j.Logger logger = LoggerFactory.getLogger(this.getClass());
private final String ASSET_TYPE = (String) "jpg";
public String handleRequest(S3Event s3event, Context context) {
....
....
t.download(Bucket,Key);


import com.amazonaws.AmazonServiceException;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectInputStream;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;


public class testDownload {
private final org.slf4j.Logger logger = LoggerFactory.getLogger(this.getClass());

public void download(String bucketName,String key) throws IOException {


try {
logger.info("Downloading an object \n");
logger.info("Building s3 client");
AmazonS3 s3 = AmazonS3ClientBuilder.standard().build();
logger.info("success");
S3Object o = s3.getObject(bucketName, key);
S3ObjectInputStream s3is = o.getObjectContent();
FileOutputStream fos = new FileOutputStream(new File(key));
byte[] read_buf = new byte[1024];
int read_len = 0;
while ((read_len = s3is.read(read_buf)) > 0) {
fos.write(read_buf, 0, read_len);
}
s3is.close();
fos.close();
} catch (AmazonServiceException e) {
logger.error(e.getErrorMessage());
System.exit(1);
} catch (FileNotFoundException e) {
logger.error(e.getMessage());
System.exit(1);
} catch (IOException e) {
logger.error(e.getMessage());
System.exit(1);
} catch (Exception e){
logger.error(e.getStackTrace().toString());
System.exit(1);
}
}

}

云日志

19:25:34,229 INFO testDownload:24 - Downloading an object 

19:25:34,229 INFO testDownload:25 - Building s3 client
END RequestId: someid
REPORT RequestId: someid Duration: 3003.13 ms Billed Duration: 3000 ms Memory Size: 128 MB Max Memory Used: 52 MB
2017-10-21T19:25:36.150Z someid Task timed out after 3.00 seconds

最佳答案

Lambda 的默认超时为 3 秒。您的 Lambda 运行了 3 秒,然后被终止。尝试将 Lambda 配置为运行更长时间。此外,您想对输出文件做什么 - 将其保存在 Lambda 计算机上?

关于lambda 中的 Java AWSClient 引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46867222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com