I have the following code, a basic lambda using print & logging.
import json
import logging
def lambda_handler(event, context):
print("Received event: " + json.dumps(event, indent=2))
print("value1 = " + event['key1'])
print("value2 = " + event['key2'])
print("value3 = " + event['key3'])
print("Will it log?")
logger = logging.getLogger()
logger.debug('This is a debug message')
logger.info('This is an info message')
logger.warning('This is a warning message')
logger.error('This is an error message')
logger.critical('This is a critical message')
return event['key1'] # Echo back the first key value
I'm trying to get it to log to cloudwatch correctly, but it only outputs when the test values are passed in, none of the other print or log statements are output. If this was a permissions issue I'm assuming this wouldn't print anything to the log? Confused!
Output:
START RequestId: a9aac29d-3e05-4bb0-baad-1e069fe60801 Version: $LATEST
value1 = Hello, Dave
value2 = value2
value3 = value3
END RequestId: a9aac29d-3e05-4bb0-baad-1e069fe60801
REPORT RequestId: a9aac29d-3e05-4bb0-baad-1e069fe60801 Duration: 1.37 ms Billed Duration: 2 ms Memory Size: 128 MB Max Memory Used: 49 MB
Test Event:
{
"key1": "Hello, Dave",
"key2": "value2",
"key3": "value3"
}


print("valueX ..." and verify the output changes