尽管GO AWS SDK没有错误,但仍无法使CloudWatchLogs工作

I have put together some code closely based on the AWS GO SDK example for the InvalidSequenceTokenException method. The SDK seems to have some bugs that I have got around and I am getting the expected response for a successful call to the API which returns the next sequence token to use for a subsequent call. Here is my code

import (
    "github.com/aws/aws-sdk-go/service/cloudwatchlogs"
    "github.com/aws/aws-sdk-go/aws"
    "github.com/opensoft/dvs-api/config"
    "strings"
)

func nextSequenceToken() (string, error) {
    params := &cloudwatchlogs.DescribeLogStreamsInput{
        LogGroupName:        aws.String(config.AwsLogGroup), // Required
        LogStreamNamePrefix: aws.String(config.AwsLogStream),
        Descending:          aws.Bool(true),
        Limit:               aws.Int64(1),
    }
    resp, err := config.AwsCloudWatchLogsSvc.DescribeLogStreams(params)
    if err != nil {
        return "", err
    }

    // Parsing from string because resp.NextToken is *always* empty ... bug?
    parsed := ""
    parts := strings.Split(resp.GoString(), "
")
    for _, part := range parts {
        if strings.Contains(part, "UploadSequenceToken") {
            parsed = strings.TrimLeft(part, "UploadSequenceToken: \"")
            parsed = strings.TrimRight(parsed, "\"")
        }
    }
    return parsed, nil
}

func LogEvent(message string, unixTime int64) error {
    nextToken, te := nextSequenceToken()
    if te != nil {
        return te
    }

    params := &cloudwatchlogs.PutLogEventsInput{
        LogEvents: []*cloudwatchlogs.InputLogEvent{// Required
            {// Required
                Message:   aws.String(message), // Required
                Timestamp: aws.Int64(unixTime), // Required
            },
            // More values...
        },
        LogGroupName:  aws.String(config.AwsLogGroup), // Required
        LogStreamName: aws.String(config.AwsLogStream), // Required
    }
    if nextToken != "" {
        params.SequenceToken = &nextToken
    }

    resp, err := config.AwsCloudWatchLogsSvc.PutLogEvents(params)
    if err != nil {
        return err
    }

    // Parsing from string because resp.NextSequenceToken is *always* empty ... bug?
    parsed := ""
    parts := strings.Split(resp.GoString(), "
")
    for _, part := range parts {
        if strings.Contains(part, "NextSequenceToken") {
            parsed = strings.TrimLeft(part, "NextSequenceToken: \"")
            parsed = strings.TrimRight(parsed, "\",")
        }
    }
    return nil
}

I also went ahead and deleted the log stream from the group just to make sure there was a connection and I did get an error back from AWS telling me the log stream is invalid and likewise, recreating the log stream fixed everything.

So my code appears to be correct, however nothing that I am logging shows up at CloudWatch Logs and my log remains empty. If I my code is correct and not returning any errors from AWS then where else should I look for problems?

Your nextSequenceToken() returns a trailing character. Here is the corrected function.

func nextSequenceToken() (string, error) {
    params := &cloudwatchlogs.DescribeLogStreamsInput{
        LogGroupName:        aws.String(config.AwsLogGroup), // Required
        LogStreamNamePrefix: aws.String(config.AwsLogStream),
        Descending:          aws.Bool(true),
        Limit:               aws.Int64(1),
    }
    resp, err := config.AwsCloudWatchLogsSvc.DescribeLogStreams(params)
    if err != nil {
        return "", err
    }

    return *(resp.LogStreams[0].UploadSequenceToken), nil
}