0

Despite using correct permissions, and trying to both print, and to log to cloudwatch, I am unable to see any output.

Here is my lambda handler:

version 1

def handler(event, context):
    print('here 1')
    for request in event['Records']:
        # do something
    print('here 4')

    return "Success"

version 2

import logging
logging.basicConfig(level = logging.INFO)
logger = logging.getLogger()

def handler(event, context):
    logger.info('here 1')
    for request in event['Records']:
        # do something
    logger.info('here 4')

    return "Success"

My code times out, and doesn't print anything to cloudwatch logs. What's the issue?

edit: IAM Permission Policies

AWSLambdaVPCAccessExecutionRole
AWSLambdaFullAccess

AWSLambdaVPCAccessExecutionRole has full cloudwatch createLogGroup, createLogStream, and PutLogEvents access.

coderboi
  • 103
  • 14
  • Can you please share the IAM policy permissions attached to the lambda? cause it seems more likely that the problem with the logs is due to a permissions issue. The timeout maybe is because of the default 3-sec lambda timeout, try to increase it to maybe 1 minute or more, depending of the load of your function. – Douglas Figueroa Mar 30 '21 at 01:00
  • even if I set the timeout to 15 minutes the lambda will still timeout – coderboi Mar 30 '21 at 03:10

1 Answers1

0

Without seeing the serverless.yml file, here is the best answer I can provide.

A quick way to verify if your function has the required permissions to log to cloudwatch.

  • Go to the AWS Lambda console
  • Find your function
  • Select Monitor

If your function doesn't have permissions to log, you'll see this message:

Warning message when function can't log

If it doesn't, it would be helpful to see the serverless.yml file (with secrets and sensitive information redacted), and then I can help further.

Aaron Stuyvenberg
  • 1,563
  • 3
  • 13
  • Aaron, the issue was with python 3.8 lambda environment. The function wouldn't work at all which is why no logs were printed. – coderboi Mar 31 '21 at 18:23