title: CloudWatch logs stream to Lambda python
body: <p>I have created a subscription filter in CloudWatch log group and made it stream to my lambda function, but am getting an error in my lambda function.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>import boto3
  import binascii
  import json
  import base64
  import zlib
  
  def stream_gzip_decompress(stream):
      dec = zlib.decompressobj(32 + zlib.MAX_WBITS)  # offset 32 to skip the header
      foo=''
      for chunk in stream:
          rv = dec.decompress(chunk)
          if rv:
              foo += rv
      return foo
  
  def lambda_handler(event, context):
      # Decode and decompress the AWS Log stream to extract json object
      stream=json.dumps(event['awslogs']['data'])
      f = base64.b64decode(stream)
      payload=json.loads(stream_gzip_decompress(f.decode(f)))
      print(payload)
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <p>Response:</p>
  
  <pre><code>{
    "errorMessage": "decode() argument 1 must be str, not bytes",
    "errorType": "TypeError",
    "stackTrace": [
      [
        "/var/task/lambda_function.py",
        34,
        "lambda_handler",
        "payload=json.loads(stream_gzip_decompress(f.decode(f)))"
      ]
    ]
  }
  </code></pre>
  
  <p>Any help or clue would be greatly appreciated! If you have any alternative solution please suggest. My requirement is to handle logs from CloudWatch using lambda.</p>
  
  <p>Thanks in Advance !!</p>