Skip to content

Cloudwatch GetLogEventsCommand not returning older logs #5559

@RoTour

Description

@RoTour

Checkboxes for prior research

Describe the bug

The command GetLogEventsCommand doesn't retrieve older logs from 2 days ago, only the ones from today when startFromHead: false, even when startTime and endTime are specified

SDK version number

@aws-sdk/client-cloudwatch-logs@3.468.0:

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v18.18.0

Reproduction Steps

Sample logs:

2023-12-06T09:21:26.823+01:00 | [SUCCESS] : DEV runner completed successfully
2023-12-06T09:22:21.392+01:00 | [CRITICAL] : API Unreachable - connect ECONNREFUSED 127.0.0.1:80
2023-12-08T09:26:30.523+01:00 | [START] [DEV] [150]; Running: https://mydomain/api; - timeout set to 10s
2023-12-08T09:26:30.665+01:00 | [SUCCESS] [DEV] [150]; Running: https://mydomain/api; In 0.142s Message: Action executed successfully
2023-12-08T09:26:31.064+01:00 | [SUCCESS] : DEV runner completed successfully
const cloudwatchConfig = {
	region: env.AWS_REGION ?? '',
	credentials: {
		accessKeyId: env.AWS_ACCESS_KEY_ID ?? '',
		secretAccessKey: env.AWS_SECRET_ACCESS_KEY ?? ''
	}
};
const cloudwatchClient = new CloudWatchLogsClient(cloudwatchConfig);
const command = new GetLogEventsCommand({
	logGroupName,
	logStreamName,
	limit: 50,
	startTime: Date.now() - (7 * 24 * 60 * 60 * 1000), // 7 days ago
	endTime: Date.now(), // Given today is december 8
	startFromHead: false
});
const data = await cloudwatchClient.send(command);
const additionalData = await cloudwatchClient.send(
	new GetLogEventsCommand({
		logGroupName,
		logStreamName,
		nextToken: data.nextForwardToken,
		startTime: Date.now() - (7 * 24 * 60 * 60 * 1000), // 7 days ago
		endTime: Date.now(),
		limit: 50
	})
);
console.log('CloudwatchLogRepository.getStreamLogsData', data.events) // Prints the 3 last logs
console.log('CloudwatchLogRepository.getStreamLogsData', additionalData.events) // []

Observed Behavior

Only returns today's logs

Expected Behavior

Should return the right amount of logs

Possible Solution

No response

Additional Information/Context

No response

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.p2This is a standard priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions