Check out the context of your function. It has property context.logStreamName. You could change it to any unique name.
Keep in mind, if you want to append your logs to existed stream, you have to persist its token. It was the reason why I created new log stream for each lambda call. Also, I am using guid for creating stream name (like: reason why log created + guid(), timestamp is ok as well).
Check more details in the next article - The Context Object (Node.js)
EDIT: Don't pay attention to my previous answer. It was completely wrong.
I checked my code how I implemented the same functionality. It isn't possible to change group or stream name from the context. But you could use CloudWatchLogs in your code for putting logs in specific group and stream.
My code:
var AWS = require('aws-sdk');
exports.handler = (event, context, callback) => {
// TODO implement
var cloudwatchlogs = new AWS.CloudWatchLogs({ apiVersion: '2014-03-28' });
// create new stream name for each request
// because I don't persist sequenceToken
var logStreamName = "myStreamName" + Math.random()
var params = {
logGroupName: 'myLogGroup',
logStreamName: logStreamName
};
cloudwatchlogs.createLogStream(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else {
var params = {
logEvents: [{
message: 'log message',
timestamp: new Date().getTime()
},
{
message: 'one more log message',
timestamp: new Date().getTime()
}
],
logGroupName: 'myLogGroup',
logStreamName: logStreamName
};
cloudwatchlogs.putLogEvents(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
}
});
callback(null, 'Hello from Lambda');
};
Disadvantages of this approach are:
- Your lambda creates two logGroups and two logStreams in accordance. One of your lambda, another custom.
console.log('') writes to lambda log, putLogEvents writes to your custom log (i.e: myStreamName0.10141409975385463). Be aware of this.
- You have to create manually 'myLogGroup' (how I did) or implement code that will create a logGroup if it doesn't exist.
The result of this testing code looks like:

My productions stream names have more sense rather name + random. And they are using guid or timestamp as a suffix. I don't think that it is safe to use random.