AWS automatically picks up any messages sent to the log or to std out (print statements) and pushes them to cloudWach as long as the role configured in the lambda function has accesses to write to the cloud watch logs. Lambda Assumes this role and uses the permissions policies to gain access to CloudWatch Logs to write the logs.
You will need a policy attached to the role like the following, or you can attach the AWS Policy called "AWSLambdaBasicExecutionRole" :
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogStreams"
],
"Resource": [
"arn:aws:logs:*:*:*"
]
}
]
}
Without the correct permissions, you will see the error in CloudWatch "There was an error loading log streams. Please try again by refreshing this page."
This Video will demonstrate the the permissions issue as well as viewing the logs in cloud watch. https://studio.youtube.com/video/0VPTlPSfFiE/edit
References:
https://geektopia.tech/post.php?blogpost=Write_To_CloudWatch_Logs_From_Lambda
https://docs.aws.amazon.com/lambda/latest/dg/monitoring-functions.html