Advertisement
jleaman

Lambda PrintPayloadToLogs Function

Sep 2nd, 2016
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. from __future__ import print_function
  2.  
  3. import json
  4. import urllib
  5. import boto3
  6.  
  7. print('Loading function')
  8.  
  9. def lambda_handler(event, context):
  10.     #print("Received event: " + json.dumps(event, indent=2))
  11.     print(event)
  12.     print(context)
  13.     return event
  14.  
  15. # Code commentary:
  16. # ·         I’m importing more than I have to, but I find that I use these often when testing.
  17. # ·         Using the ‘print()’ function, I’m writing directly to CloudWatch logs.  This is very helpful for troubleshooting.
  18. # ·         Line: ‘def lambda_handler(event, context):’  is what allows you to view and manipulate the payload, which is the event.  This function also comes with a second argument ‘context’.
  19. # ·         There are many use-cases for Lambda, but I find a good first step to print both the event and context to logs and move forward from there.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement