【发布时间】:2019-01-07 10:33:46
【问题描述】:
我们正在处理 AWS Lambda 和 Cloudwatch 日志。现在,我想在不使用 Java 的 logStreamName 的情况下从 Cloudwatch 日志中获取所有日志事件。
由于我们是以动态方式生成日志流,我不确定如何从 Cloudwatch 日志组中获取所有日志。
我知道,如果我们有日志流名称,那么我们可以使用下面的代码
ClientConfiguration clientConfig = getClientConfig();
AWSLogsClientBuilder builder = AWSLogsClientBuilder.standard();
AWSLogs logsClient= builder.withCredentials(new AWSStaticCredentialsProvider(new ProfileCredentialsProvider(profile).getCredentials())).withRegion(Regions.AP_SOUTHEAST_2).withClientConfiguration(clientConfig).build();
GetLogEventsRequest request = new GetLogEventsRequest()
.withStartTime(1531231200000L)
.withEndTime(1531576800000L)
.withLogGroupName("FlowLogs_GroupName")
.withLogStreamName("eni-xxxxx");
GetLogEventsResult result = logsClient.getLogEvents(request);
result.getEvents().forEach(outputLogEvent -> {
System.out.println(outputLogEvent.getMessage());
});
由于是 AWS 新手,谁能帮我提供一些代码示例?
【问题讨论】:
标签: java amazon-web-services aws-lambda amazon-cloudwatchlogs