1

We have a custom logger created with winston npm for our nodejs applications. In this custom logger, we will create a logging location with the following piece of code.

const LOG_LOCATION = `${__dirname}/../logs`;
if (!fs.existsSync(LOG_LOCATION)) {
  fs.mkdirSync(LOG_LOCATION);
}

I'm just wondering whether the log location creation will work in a server-less environment (lambda)?

Thanks,

2 Answers 2

4

It will not work in lambda. Since the only writable location in Lambda is /tmp. Rest of the directories are read-only.

Logging is automatically taken care of sending them to Cloudwatch which is a log distributed system.

Sign up to request clarification or add additional context in comments.

Comments

3

If you're running Javascript & Node.js in AWS Lambda, you should use the console object.

Some examples:

console.log('A custom log message here')

try {
  something_will_go_wrong()
} catch(err) {
  console.error(err)
}

Lambda platform will automatically pick up everything output to console and pipe it to a CloudWatch Logs Stream. You can later inspect your logs in CloudWatch console or use a specialized tool like Dashbird to receive alerts and investigate errors connected to other services used by the Lambda, such as S3 or DynamoDB for example.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.