0
votes

I have configured AWS CloudWatch alarm which send me email when there is any error across any of the lambda functions.

I want to check name of Lambda function in which error has occurred in the email is there any way to do that ?

1

1 Answers

0
votes

In the event of failure, you receive all the information including the function name. Below is an example event of failure. So you have to write some code extract the information from this event and then send an email.

check out this blog post How to get notified on specific Lambda function error patterns using CloudWatch you can use.

{
    "version": "0",
    "id": "66b5bd02-ac25-e43f-f8b9-da1ff0568d75",
    "detail-type": "AWS API Call via CloudTrail",
    "source": "aws.lambda",
    "account": "1234567890",
    "time": "2021-01-22T13:36:29Z",
    "region": "us-east-1",
    "resources": [],
    "detail": {
        "eventVersion": "1.08",
        "userIdentity": {
            "type": "IAMUser",
            "principalId": "fsfdsfdsfsd",
            "arn": "arn:aws:iam::1234567890:user/myusername",
            "accountId": "1234567890",
            "accessKeyId": "adsadasdasdsadas",
            "userName": "myusername",
            "sessionContext": {
                "sessionIssuer": {},
                "webIdFederationData": {},
                "attributes": {
                    "mfaAuthenticated": "true",
                    "creationDate": "2021-01-22T09:40:15Z"
                }
            }
        },
        "eventTime": "2021-01-22T13:36:29Z",
        "eventSource": "lambda.amazonaws.com",
        "eventName": "UpdateFunctionCode20150331v2",
        "awsRegion": "us-east-1",
        "sourceIPAddress": "192.168.1.1",
        "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Safari/605.1.15",
        "requestParameters": {
            "functionName": "arn:aws:lambda:us-east-1:1234567890:function:myfunction",
            "publish": false,
            "dryRun": false
        },
        "responseElements": {
            "functionName": "myfunction",
            "functionArn": "arn:aws:lambda:us-east-1:1234567890:function:myfunction",
            "runtime": "python3.7",
            "role": "arn:aws:iam::1234567890:role/service-role/myfunction-role-c1brzxg3",
            "handler": "lambda_function.lambda_handler",
            "codeSize": 197,
            "description": "A starter AWS Lambda function.",
            "timeout": 3,
            "memorySize": 128,
            "lastModified": "2021-01-22T13:36:29.377+0000",
            "codeSha256": "durTPkHgnBr2hM1tLnybH0mey0AifhFCEbT0Qdteus8=",
            "version": "$LATEST",
            "environment": {},
            "tracingConfig": {
                "mode": "PassThrough"
            },
            "revisionId": "3d7e813e-2da4-46ef-97e8-05beeb49d01c",
            "state": "Active",
            "lastUpdateStatus": "Successful",
            "packageType": "Zip"
        },
        "requestID": "7fd4d185-af44-4a9a-b463-648144f1aa12",
        "eventID": "77790729-9e12-440c-afa1-c5b1c611c876",
        "readOnly": false,
        "eventType": "AwsApiCall",
        "managementEvent": true,
        "eventCategory": "Management"
    }
}