gpt4 book ai didi

java - AWS Lambda Java函数成功但超时

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

我创建了一个基本的 AWS Lambda java 函数来将 xml 消息转换为 json。该函数由 S3 事件触发(消息被转换并丢弃在不同的 S3 存储桶中)。看起来很成功,我可以看到 cloudwatch 中的步骤,并且转换后的消息位于 S3 目标存储桶中。但是,我在云监视日志中看到超时警告(将超时设置为 15 秒)。我一定错过了一些东西,对于 Lambda 来说,我绝对是个新手。我需要提供完成或成功的背景吗?任何建议或提示将不胜感激。

代码片段:

    public void msgConvertToJson(S3Event s3event, Context context) {

final String key = s3event.getRecords().get(0).getS3().getObject().getKey();
final String bucketName = s3event.getRecords().get(0).getS3().getBucket().getName();
log.info("key: " + key + " bucketName:" + bucketName);
String action = "";


try {

//Attempt to retrieve the message from S3 on notification
log.info("attempting to get message");
action = "get";
final String message = s3Client.getObjectAsString(bucketName, key);

//Attempt to parse and convert the message to JSON
log.info("attempting to parse message");
String msgJson = new MessageParser(message).getMessageJson();

//Attempt to write the converted message to a new S3 bucket
final String parsedBucket = "parsed-" + bucketName;
final String newKey = key.replace(".xml",".json");
log.info("newKey: " + newKey + " parsedBucketName:" + parsedBucket);
log.info("attempting to put message");
action = "put";

s3Client.putObject(parsedBucket, newKey, msgJson );

} catch (AmazonServiceException ase) {
log.error("Caught an AmazonServiceException trying to " + action + " file " + key + ", which " +
"means your request made it " +
"to Amazon S3, but was rejected with an error response" +
" for some reason.");
log.error("Error Message: " + ase.getMessage());
log.error("HTTP Status Code: " + ase.getStatusCode());
log.error("AWS Error Code: " + ase.getErrorCode());
log.error("Error Type: " + ase.getErrorType());
log.error("Request ID: " + ase.getRequestId());
} catch (AmazonClientException ace) {
log.error("Caught an AmazonClientException while trying to " + action + " file " + key + ", which " +
"means the client encountered " +
"an internal error while trying to " +
"communicate with S3, " +
"such as not being able to access the network.");
log.error("Error Message: " + ace.getMessage());
}
}

最佳答案

事实证明,只是超时时间太短了。 JVM 的冷启动时间肯定比我想象的要长。我只是假设我的代码中有另一个问题。将内存增加到 192,超时时间增加到 45 秒。希望这对其他人有帮助。

真的很不幸,有人向我指出了错误的信息(NodeJS)而不是 Java,从而对我进行了标记。

关于java - AWS Lambda Java函数成功但超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44592402/

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