can you send amazon lambda error logs via email





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















is there a way to send via email the same error log that would appear in cloudwatch for a Lambda function?










share|improve this question























  • what part of cloudwatch logs do you want to email ?

    – varnit
    Jan 3 at 14:20











  • @varnit what do you mean? The full log relating to the lambda that failed obviously.

    – Blue Moon
    Jan 3 at 14:34











  • i mean do you want just the exception that might occur in your lambda function or execution time and other extra stuff that are part of cloudwatch log

    – varnit
    Jan 3 at 14:37











  • The exception is what I am mainly after. Other information would be useful too but If complicated to get is not strictly necessary.

    – Blue Moon
    Jan 3 at 14:39






  • 1





    yes you can you need to write a lambda where you can use client.describe_log_streams and extarct the log and make it formatted and then in that lambda you can do sns.publish and make formatted string of that log extratcion and send over.....

    – Rajarshi Das
    Jan 3 at 14:59




















1















is there a way to send via email the same error log that would appear in cloudwatch for a Lambda function?










share|improve this question























  • what part of cloudwatch logs do you want to email ?

    – varnit
    Jan 3 at 14:20











  • @varnit what do you mean? The full log relating to the lambda that failed obviously.

    – Blue Moon
    Jan 3 at 14:34











  • i mean do you want just the exception that might occur in your lambda function or execution time and other extra stuff that are part of cloudwatch log

    – varnit
    Jan 3 at 14:37











  • The exception is what I am mainly after. Other information would be useful too but If complicated to get is not strictly necessary.

    – Blue Moon
    Jan 3 at 14:39






  • 1





    yes you can you need to write a lambda where you can use client.describe_log_streams and extarct the log and make it formatted and then in that lambda you can do sns.publish and make formatted string of that log extratcion and send over.....

    – Rajarshi Das
    Jan 3 at 14:59
















1












1








1








is there a way to send via email the same error log that would appear in cloudwatch for a Lambda function?










share|improve this question














is there a way to send via email the same error log that would appear in cloudwatch for a Lambda function?







amazon-web-services logging aws-lambda amazon-cloudwatch






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 3 at 13:58









Blue MoonBlue Moon

1,30542252




1,30542252













  • what part of cloudwatch logs do you want to email ?

    – varnit
    Jan 3 at 14:20











  • @varnit what do you mean? The full log relating to the lambda that failed obviously.

    – Blue Moon
    Jan 3 at 14:34











  • i mean do you want just the exception that might occur in your lambda function or execution time and other extra stuff that are part of cloudwatch log

    – varnit
    Jan 3 at 14:37











  • The exception is what I am mainly after. Other information would be useful too but If complicated to get is not strictly necessary.

    – Blue Moon
    Jan 3 at 14:39






  • 1





    yes you can you need to write a lambda where you can use client.describe_log_streams and extarct the log and make it formatted and then in that lambda you can do sns.publish and make formatted string of that log extratcion and send over.....

    – Rajarshi Das
    Jan 3 at 14:59





















  • what part of cloudwatch logs do you want to email ?

    – varnit
    Jan 3 at 14:20











  • @varnit what do you mean? The full log relating to the lambda that failed obviously.

    – Blue Moon
    Jan 3 at 14:34











  • i mean do you want just the exception that might occur in your lambda function or execution time and other extra stuff that are part of cloudwatch log

    – varnit
    Jan 3 at 14:37











  • The exception is what I am mainly after. Other information would be useful too but If complicated to get is not strictly necessary.

    – Blue Moon
    Jan 3 at 14:39






  • 1





    yes you can you need to write a lambda where you can use client.describe_log_streams and extarct the log and make it formatted and then in that lambda you can do sns.publish and make formatted string of that log extratcion and send over.....

    – Rajarshi Das
    Jan 3 at 14:59



















what part of cloudwatch logs do you want to email ?

– varnit
Jan 3 at 14:20





what part of cloudwatch logs do you want to email ?

– varnit
Jan 3 at 14:20













@varnit what do you mean? The full log relating to the lambda that failed obviously.

– Blue Moon
Jan 3 at 14:34





@varnit what do you mean? The full log relating to the lambda that failed obviously.

– Blue Moon
Jan 3 at 14:34













i mean do you want just the exception that might occur in your lambda function or execution time and other extra stuff that are part of cloudwatch log

– varnit
Jan 3 at 14:37





i mean do you want just the exception that might occur in your lambda function or execution time and other extra stuff that are part of cloudwatch log

– varnit
Jan 3 at 14:37













The exception is what I am mainly after. Other information would be useful too but If complicated to get is not strictly necessary.

– Blue Moon
Jan 3 at 14:39





The exception is what I am mainly after. Other information would be useful too but If complicated to get is not strictly necessary.

– Blue Moon
Jan 3 at 14:39




1




1





yes you can you need to write a lambda where you can use client.describe_log_streams and extarct the log and make it formatted and then in that lambda you can do sns.publish and make formatted string of that log extratcion and send over.....

– Rajarshi Das
Jan 3 at 14:59







yes you can you need to write a lambda where you can use client.describe_log_streams and extarct the log and make it formatted and then in that lambda you can do sns.publish and make formatted string of that log extratcion and send over.....

– Rajarshi Das
Jan 3 at 14:59














1 Answer
1






active

oldest

votes


















0














To deliver logs you can create cloudwatch subscription filter, you can click on your log group and then click on stream on AWS lambda and select your lambda function .



stream to aws lambda



the logs will be delivered in gzip format and you can unzip them using this code



var AWS = require('aws-sdk');
var zlib = require('zlib');
// Set the region
AWS.config.update({region: 'REGION'});

// Create sendTemplatedEmail params
var params = {
Destination: { /* required */
CcAddresses: [
'EMAIL_ADDRESS',
/* more CC email addresses */
],
ToAddresses: [
'EMAIL_ADDRESS',
/* more To email addresses */
]
},
Source: 'EMAIL_ADDRESS', /* required */
Template: 'TEMPLATE_NAME', /* required */
TemplateData: '{ "REPLACEMENT_TAG_NAME":"REPLACEMENT_VALUE" }', /* required */
ReplyToAddresses: [
'EMAIL_ADDRESS',
],
};

exports.handler = function(input, context) {
var payload = new Buffer(input.awslogs.data, 'base64');
zlib.gunzip(payload, function(e, result) {
if (e) {
context.fail(e);
} else {
result = JSON.parse(result.toString('ascii'));
console.log("Event Data:", JSON.stringify(result, null, 2));
var sendPromise = new AWS.SES({apiVersion: '2010-12-
01'}).sendTemplatedEmail(params).promise();

// Handle promise's fulfilled/rejected states
sendPromise.then(
function(data) {
console.log(data);
}).catch(
function(err) {
console.error(err, err.stack);
});
context.succeed();
}
});
};


This code basically fetch the logs, unzip them and email it using AWS SES
sdk for more information click on these resources.



cloudwatch log lambda subscription
Sending email using Simple email service sdk






share|improve this answer


























  • I'm sorry you have to use cloudwatch subscribtion filter for delivering logs to email

    – varnit
    Jan 3 at 15:07











  • updated the answer check it out

    – varnit
    Jan 3 at 15:19












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54023760%2fcan-you-send-amazon-lambda-error-logs-via-email%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














To deliver logs you can create cloudwatch subscription filter, you can click on your log group and then click on stream on AWS lambda and select your lambda function .



stream to aws lambda



the logs will be delivered in gzip format and you can unzip them using this code



var AWS = require('aws-sdk');
var zlib = require('zlib');
// Set the region
AWS.config.update({region: 'REGION'});

// Create sendTemplatedEmail params
var params = {
Destination: { /* required */
CcAddresses: [
'EMAIL_ADDRESS',
/* more CC email addresses */
],
ToAddresses: [
'EMAIL_ADDRESS',
/* more To email addresses */
]
},
Source: 'EMAIL_ADDRESS', /* required */
Template: 'TEMPLATE_NAME', /* required */
TemplateData: '{ "REPLACEMENT_TAG_NAME":"REPLACEMENT_VALUE" }', /* required */
ReplyToAddresses: [
'EMAIL_ADDRESS',
],
};

exports.handler = function(input, context) {
var payload = new Buffer(input.awslogs.data, 'base64');
zlib.gunzip(payload, function(e, result) {
if (e) {
context.fail(e);
} else {
result = JSON.parse(result.toString('ascii'));
console.log("Event Data:", JSON.stringify(result, null, 2));
var sendPromise = new AWS.SES({apiVersion: '2010-12-
01'}).sendTemplatedEmail(params).promise();

// Handle promise's fulfilled/rejected states
sendPromise.then(
function(data) {
console.log(data);
}).catch(
function(err) {
console.error(err, err.stack);
});
context.succeed();
}
});
};


This code basically fetch the logs, unzip them and email it using AWS SES
sdk for more information click on these resources.



cloudwatch log lambda subscription
Sending email using Simple email service sdk






share|improve this answer


























  • I'm sorry you have to use cloudwatch subscribtion filter for delivering logs to email

    – varnit
    Jan 3 at 15:07











  • updated the answer check it out

    – varnit
    Jan 3 at 15:19
















0














To deliver logs you can create cloudwatch subscription filter, you can click on your log group and then click on stream on AWS lambda and select your lambda function .



stream to aws lambda



the logs will be delivered in gzip format and you can unzip them using this code



var AWS = require('aws-sdk');
var zlib = require('zlib');
// Set the region
AWS.config.update({region: 'REGION'});

// Create sendTemplatedEmail params
var params = {
Destination: { /* required */
CcAddresses: [
'EMAIL_ADDRESS',
/* more CC email addresses */
],
ToAddresses: [
'EMAIL_ADDRESS',
/* more To email addresses */
]
},
Source: 'EMAIL_ADDRESS', /* required */
Template: 'TEMPLATE_NAME', /* required */
TemplateData: '{ "REPLACEMENT_TAG_NAME":"REPLACEMENT_VALUE" }', /* required */
ReplyToAddresses: [
'EMAIL_ADDRESS',
],
};

exports.handler = function(input, context) {
var payload = new Buffer(input.awslogs.data, 'base64');
zlib.gunzip(payload, function(e, result) {
if (e) {
context.fail(e);
} else {
result = JSON.parse(result.toString('ascii'));
console.log("Event Data:", JSON.stringify(result, null, 2));
var sendPromise = new AWS.SES({apiVersion: '2010-12-
01'}).sendTemplatedEmail(params).promise();

// Handle promise's fulfilled/rejected states
sendPromise.then(
function(data) {
console.log(data);
}).catch(
function(err) {
console.error(err, err.stack);
});
context.succeed();
}
});
};


This code basically fetch the logs, unzip them and email it using AWS SES
sdk for more information click on these resources.



cloudwatch log lambda subscription
Sending email using Simple email service sdk






share|improve this answer


























  • I'm sorry you have to use cloudwatch subscribtion filter for delivering logs to email

    – varnit
    Jan 3 at 15:07











  • updated the answer check it out

    – varnit
    Jan 3 at 15:19














0












0








0







To deliver logs you can create cloudwatch subscription filter, you can click on your log group and then click on stream on AWS lambda and select your lambda function .



stream to aws lambda



the logs will be delivered in gzip format and you can unzip them using this code



var AWS = require('aws-sdk');
var zlib = require('zlib');
// Set the region
AWS.config.update({region: 'REGION'});

// Create sendTemplatedEmail params
var params = {
Destination: { /* required */
CcAddresses: [
'EMAIL_ADDRESS',
/* more CC email addresses */
],
ToAddresses: [
'EMAIL_ADDRESS',
/* more To email addresses */
]
},
Source: 'EMAIL_ADDRESS', /* required */
Template: 'TEMPLATE_NAME', /* required */
TemplateData: '{ "REPLACEMENT_TAG_NAME":"REPLACEMENT_VALUE" }', /* required */
ReplyToAddresses: [
'EMAIL_ADDRESS',
],
};

exports.handler = function(input, context) {
var payload = new Buffer(input.awslogs.data, 'base64');
zlib.gunzip(payload, function(e, result) {
if (e) {
context.fail(e);
} else {
result = JSON.parse(result.toString('ascii'));
console.log("Event Data:", JSON.stringify(result, null, 2));
var sendPromise = new AWS.SES({apiVersion: '2010-12-
01'}).sendTemplatedEmail(params).promise();

// Handle promise's fulfilled/rejected states
sendPromise.then(
function(data) {
console.log(data);
}).catch(
function(err) {
console.error(err, err.stack);
});
context.succeed();
}
});
};


This code basically fetch the logs, unzip them and email it using AWS SES
sdk for more information click on these resources.



cloudwatch log lambda subscription
Sending email using Simple email service sdk






share|improve this answer















To deliver logs you can create cloudwatch subscription filter, you can click on your log group and then click on stream on AWS lambda and select your lambda function .



stream to aws lambda



the logs will be delivered in gzip format and you can unzip them using this code



var AWS = require('aws-sdk');
var zlib = require('zlib');
// Set the region
AWS.config.update({region: 'REGION'});

// Create sendTemplatedEmail params
var params = {
Destination: { /* required */
CcAddresses: [
'EMAIL_ADDRESS',
/* more CC email addresses */
],
ToAddresses: [
'EMAIL_ADDRESS',
/* more To email addresses */
]
},
Source: 'EMAIL_ADDRESS', /* required */
Template: 'TEMPLATE_NAME', /* required */
TemplateData: '{ "REPLACEMENT_TAG_NAME":"REPLACEMENT_VALUE" }', /* required */
ReplyToAddresses: [
'EMAIL_ADDRESS',
],
};

exports.handler = function(input, context) {
var payload = new Buffer(input.awslogs.data, 'base64');
zlib.gunzip(payload, function(e, result) {
if (e) {
context.fail(e);
} else {
result = JSON.parse(result.toString('ascii'));
console.log("Event Data:", JSON.stringify(result, null, 2));
var sendPromise = new AWS.SES({apiVersion: '2010-12-
01'}).sendTemplatedEmail(params).promise();

// Handle promise's fulfilled/rejected states
sendPromise.then(
function(data) {
console.log(data);
}).catch(
function(err) {
console.error(err, err.stack);
});
context.succeed();
}
});
};


This code basically fetch the logs, unzip them and email it using AWS SES
sdk for more information click on these resources.



cloudwatch log lambda subscription
Sending email using Simple email service sdk







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 3 at 15:17

























answered Jan 3 at 14:46









varnitvarnit

1,306519




1,306519













  • I'm sorry you have to use cloudwatch subscribtion filter for delivering logs to email

    – varnit
    Jan 3 at 15:07











  • updated the answer check it out

    – varnit
    Jan 3 at 15:19



















  • I'm sorry you have to use cloudwatch subscribtion filter for delivering logs to email

    – varnit
    Jan 3 at 15:07











  • updated the answer check it out

    – varnit
    Jan 3 at 15:19

















I'm sorry you have to use cloudwatch subscribtion filter for delivering logs to email

– varnit
Jan 3 at 15:07





I'm sorry you have to use cloudwatch subscribtion filter for delivering logs to email

– varnit
Jan 3 at 15:07













updated the answer check it out

– varnit
Jan 3 at 15:19





updated the answer check it out

– varnit
Jan 3 at 15:19




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54023760%2fcan-you-send-amazon-lambda-error-logs-via-email%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

ts Property 'filter' does not exist on type '{}'

mat-slide-toggle shouldn't change it's state when I click cancel in confirmation window