Skip to content
Advertisement

How to view stdout in AWS environment?

Below is the lambda function:

exports.lendingLambdaHandler = async (event, context) => {
    const records = event.Records

    console.log(records)

    return {}
};

executed with NodeJS runtime ( as serverless app) that writes the incoming event record to stdout

By definition, console.log prints to stdout, as mentioned here, but I need to go through cloud watch logs, as this is AWS serverless app:

enter image description here


What is the correct way to view stdout in AWS environment?

Advertisement

Answer

Lambda function is serverless right, but that doesn’t mean that there is no server running your lambda function, all it really means is that you don’t see that server and don’t have to manage it at all.

When you invoke lambda function, there is a fleet of servers waiting to launch a new docker container in which your lambda function is going to be executed (or reuse existing execution context if your lambda function is being invoked constantly), the bottom line is that stdout in case of lambda is the same stdout as if you have run the code locally (or on a server which you have access to), the difference is that you don’t have access to that underlying docker container where you would observe it. Hence the logs are also being sent to CW Logs so that you have a way of accessing them.

What is the correct way to view stdout in AWS environment?

As I have mentioned, you don’t have access to the underlying container in which your lambda function is being executed so the correct way of accessing logs is through CW Logs. Of course, you may choose to stream the logs from CW to any other service as you like or as your use case requires.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement