Skip to content

InvalidSequenceTokenException #12

@plutext

Description

@plutext

From AWS Lamba, you might get:

com.amazonaws.AmazonServiceException: Unable to unmarshall exception response with the unmarshallers provided (Service: AWSLogs; Status Code: 400; Error Code: InvalidSequenceTokenException; Request ID: 5645e9c0-5552-11e9-b9f8-71f29888b2c7)

    at com.amazonaws.services.logs.AWSLogsClient.doInvoke(AWSLogsClient.java:2447)
    at com.amazonaws.services.logs.AWSLogsClient.invoke(AWSLogsClient.java:2423)
    at com.amazonaws.services.logs.AWSLogsClient.executePutLogEvents(AWSLogsClient.java:1951)
    at com.amazonaws.services.logs.AWSLogsClient.putLogEvents(AWSLogsClient.java:1926)

This seems to fix it:

        try {
        	nextToken = awsLogs.putLogEvents(
                    logEventReq
                            .withSequenceToken(nextToken)
                            .withLogEvents(events)
            ).getNextSequenceToken();
        	
		} catch (final InvalidSequenceTokenException iste) {
			
			// Copy https://github.com/graingert/cloudwatch-logback-appender/blob/master/src/main/java/com/brickcommerce/aws/logging/CloudWatchWriter.java#L67
			System.err.println("InvalidSequenceTokenException, will reset the token to the expected one");
			nextToken = iste.getExpectedSequenceToken();

		} catch (com.amazonaws.AmazonServiceException ase) {
			
			// But as per stack trace copied above this is what is actually caught on Lambda
			
			// Unable to unmarshall exception response with the unmarshallers provided 
			// (Service: AWSLogs; Status Code: 400; Error Code: InvalidSequenceTokenException; Request ID: 5ad1e6cc-5fdc-11e9-bdef-8759912c2f97
			System.err.println("Response wrapped InvalidSequenceTokenException, will reset the token to the expected one");
			
		    LogStream stream = findLogStream(groupName, currentStreamName);
            nextToken = stream.getUploadSequenceToken();
			
		} catch (Exception e) {
			logContext.addError("Exception while adding log events.", e);
		}

See also https://stackoverflow.com/questions/36876563/amazon-cloud-watch-log-putlogeventsrequest-the-given-sequencetoken-is-invali for reports of this error using other logging libs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions