首先,我想提到我是AWS和Kafka的新手。
每当生产者在主题中进行生产时,部署在AWS EC2实例上的我的Kafka服务器都会触发lambda。 lambda函数尝试从该主题调用使用者api进行消费,但是lambda尝试创建的http连接由于超时而失败。 lambda函数与kafka服务器位于同一vpc中。
我尝试了以下操作:
URL url = new URL("http://ec2-*-*-*-*.ap-south-1.compute.amazonaws.com/consumers/db_json_consumer/instances/lambda_consumer/topics/kbtest");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Accept", "application/json");
logger.log("Connection : " + conn);
conn.connect();
if (conn.getResponseCode() != 200) {
logger.log("Failed : HTTP error code : " + conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
logger.log("\nSending 'GET' request to URL : " + url);
logger.log("Response Code : " + conn.getResponseCode());
conn.disconnect();
}
Execution result: failed(logs)
Details
The area below shows the result returned by your function execution. Learn more about returning results from your function.
{
"errorMessage": "2019-06-24T12:25:08.529Z 406d0e22-3283-4f02-9c31-cb2163c1b950 Task timed out after 15.02 seconds"
}
Summary
Code SHA-256
Mn3/26Ky/hBE1ONL+LDdYaLEiCQZo6VHdlfcRpF8WYw=
Request ID
406d0e22-3283-4f02-9c31-cb2163c1b950
Duration
15015.27 ms
Billed duration
15000 ms
Resources configured
512 MB
Max memory used
55 MB
Log output
The section below shows the logging calls in your code. These correspond to a single row within the CloudWatch log group corresponding to this Lambda function. Click here to view the CloudWatch log group.
START RequestId: 406d0e22-3283-4f02-9c31-cb2163c1b950 Version: $LATEST
Heyy lambda object : HeyConnection : sun.net.www.protocol.http.HttpURLConnection:http://13.235.76.198:8082/consumers/db_json_consumer/instances/lambda_consumer/topics/kbtestEND RequestId: 406d0e22-3283-4f02-9c31-cb2163c1b950
REPORT RequestId: 406d0e22-3283-4f02-9c31-cb2163c1b950 Duration: 15015.27 ms Billed Duration: 15000 ms Memory Size: 512 MB Max Memory Used: 55 MB
2019-06-24T12:25:08.529Z 406d0e22-3283-4f02-9c31-cb2163c1b950 Task timed out after 15.02 seconds