title: AWS Lambda with Python write to CloudWatch throw DataAlreadyAcceptedException
body: <p>Hi I am building a AWS lambda function with API Gateway to write the log from ngx-logger in my Angular project to CloudWatch. Here is the python lambda function</p>
  
  <pre><code>def log(event, context):
      log_streams = logs.describe_log_streams(logGroupName=LOG_GROUP)
      nextSequenceToken=log_streams['logStreams'][0]['uploadSequenceToken']
  
      timestamp = int(round(time.time() * 1000))
  
      result = logs.put_log_events(
          logGroupName=LOG_GROUP,
          logStreamName=LOG_STREAM,
          logEvents=[
              {
                  'timestamp': timestamp,
                  'message': Hello world, here is our first log message!'
              }
          ],
          sequenceToken=nextSequenceToken)
  
      return {
      'statusCode': 200,
      'body': json.dumps('Hello from Lambda!')
  }
  </code></pre>
  
  <p>However, when I trigger my frontend with a few errors, I can see some errors are logged while some errors are not with the following exception</p>
  
  <pre><code>DataAlreadyAcceptedException: An error occurred (DataAlreadyAcceptedException) when calling the PutLogEvents operation: The given batch of log events has already been accepted. The next batch can be sent with sequenceToken: xxxxxxxxxxxxxxxxxxx
  </code></pre>
  
  <p>I am thing if it is because Lambda is async and two requests get the same next sequence number. Is there any way I can avoid this issue? Thank you</p>