AWS (GovCloud) Lambda Destination Not Triggering

Viewed 218

I am working in AWS GovCloud I have the following configuration in AWS Lambda:

  1. A Lambda function which decodes a payload
  2. A Kinesis Stream set as a trigger for the aforementioned function
  3. A Lambda Destination (we have tried Lambda functions as well as SQS, SNS)

No matter the configuration, I cannot seem to get Lambda to trigger the destination function (or queue in the event of SQS).

Here is the current Lambda Function. I have tried many permutations of the result/return payload without avail.

import base64
import json

def lambda_handler(event, context):
    #print("Received event: " + json.dumps(event, indent=2))
    for record in event['Records']:
        payload = base64.b64decode(record['kinesis']['data']).decode('utf-8', 'ignore')
        print("Success")
        result = {
        "statusCode": 202,
        "headers": {
        #'Content-Type': 'application/json',
            },
        "body": '{payload}'
        }
    
    return json.dumps(result)

I then send a message to Kinesis with the AWS CLI (I have noted that "Test" in the console does not observe desintations as per Jared Short ).

Every 0.1s: aws kinesis put-records --stream-name test-stream --records Data=SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IGZyb20gdGhlIEFXUyBDTEkh,PartitionKey=partitionkey1                            Thu Jul  8 19:03:54 2021

{
    "FailedRecordCount": 0,
    "Records": [
        {
            "SequenceNumber": "49619938447946944252072058244333476686328287240252293122",
            "ShardId": "shardId-000000000000"
        }
    ]
}

Using Cloudwatch metrics and logs I am able to observe the function being triggered by the messages sent to Kinesis every .1 second.

enter image description here

The metrics charts indicate a success (as I expect).

Here is an example log from Cloudwatch:

START RequestId: 0cf3fb87-06e6-4e35-9de8-b30147e7be9d Version: $LATEST
Loading function
Success
END RequestId: 0cf3fb87-06e6-4e35-9de8-b30147e7be9d
REPORT RequestId: 0cf3fb87-06e6-4e35-9de8-b30147e7be9d  Duration: 1.27 ms   Billed Duration: 2 ms   Memory Size: 128 MB Max Memory Used: 51 MB  Init Duration: 113.64 ms    
START RequestId: e663fa4a-2d0b-42d6-9e38-599712b71101 Version: $LATEST
Success
END RequestId: e663fa4a-2d0b-42d6-9e38-599712b71101
REPORT RequestId: e663fa4a-2d0b-42d6-9e38-599712b71101  Duration: 1.04 ms   Billed Duration: 2 ms   Memory Size: 128 MB Max Memory Used: 51 MB  
START RequestId: b1373bbe-d2c6-49fb-a71f-dcedaf9210eb Version: $LATEST
Success
END RequestId: b1373bbe-d2c6-49fb-a71f-dcedaf9210eb
REPORT RequestId: b1373bbe-d2c6-49fb-a71f-dcedaf9210eb  Duration: 0.98 ms   Billed Duration: 1 ms   Memory Size: 128 MB Max Memory Used: 51 MB  
START RequestId: e0382653-9c33-44d6-82a7-a82f0f416297 Version: $LATEST
Success
END RequestId: e0382653-9c33-44d6-82a7-a82f0f416297
REPORT RequestId: e0382653-9c33-44d6-82a7-a82f0f416297  Duration: 1.05 ms   Billed Duration: 2 ms   Memory Size: 128 MB Max Memory Used: 51 MB  
START RequestId: f9600ef5-419f-4271-9680-7368ccc5512d Version: $LATEST
Success

However, viewing the cloudwatch logs/metrics for the destination lambda function or SQS queue clearly show that the destination is not being triggered.

Over the course of troubleshooting, I have over-provisioned IAM policies to the Lambda function execution role so I am fairly confident that it is not an IAM related issue. Additionally, both functions are sharing the same execution role.

One thing I am not clear on after reviewing AWS documentation and 3rd party information is the criteria by which AWS determines success or failure for a given function. I am currently researching the invokation docs in search of what might be wrong here - but my interpretation is that AWS knows our function is successful based on the above Cloudwatch metrics showing a 100% success rate.

Does anyone know what I am doing wrong or how to try to troubleshoot the destination trigger for lambda?

Edit: As pointed out, the code is not correct for multiple record events. This is a function of senseless troubleshooting/changes to the code to get the Destination to trigger. Even something as simple as this does not invoke the destination.

import base64
import json

def lambda_handler(event, context):
    #print("Received event: " + json.dumps(event, indent=2))
    # for record in event['Records']:
    #     payload = base64.b64decode(record['kinesis']['data']).decode('utf-8', 'ignore')
    #     print("Success")
    #     result = {
    #     "statusCode": 202,
    #     "headers": {
    #     'Content-Type': 'application/json',
    #         },
    #     "body": '{"Success":True, payload}'
    #     }

    return { "result": "OK" }

So, the question: Can someone demonstrate it is possible to have a Kinesis Stream Event Source Trigger a Lambda Function which successfully triggers a Lambda destination in AWS Govcloud?

0 Answers
Related