0
votes

I have an AWS Lambda Function which takes a ZipCode and finds locations within a radius. Each location returned is processed further by running it through a series of business processes. My test data is comprised of 24 locations being returned for each request. Each request has a guid that represents the request I'm peppering my code with console.log statements so I can follow what's happening via CloudWatch logs.

Whenever I run the lambda function, the CloudWatch log Ends before the process finishes. I subsequently make another request to Lambda with a different Guid and I see entries in CLoudWatch log for the previous request.

How come CloudWatch is not staying active and capturing log entries throughout the entire process? - I'm assuming that Lambda function ends as soon as "End" shows up in CloudWatch Log.

How come log entries from a previous request are showing up muddled in with a subsequent request?

UPDATE

The data construct containing the 24 locations comes from an async method. Each of the 24 locations is a Task. Because async is a promise of future results, is it possible the lambda function is closing down before the async is satisfied? This could explain why only a handful of the 24 locations are outputted in CLoudWatch log before the "End" is registered. There's no consistency as to how many of the 24 are processed/logged before the "End" event happens. The subsequent call seems to pick up the balance from the original call.

1
How long ate you waiting between requests? CWL take about 20 seconds to show up. Do they have the same request id or different (ie do the old CW logs appear with the same request id as the new request?)hephalump
Each request to Lambda function is a different Guid. Sometimes I’ll do a second or third subsequent request within 30 seconds. Other times I’ll leave it alone. I’ll regret CWL but it does not show updates. After awhile I’ll make a new request and then CWL updates and I see mix bag of entries in CWL based on request ID.Tom Schreck
The headline sounds misleading. Isn't your problem just that the logs don't appear in time in CloudWatch Logs?Dunedan

1 Answers

0
votes

I figured out the issue. The problem I'm experiencing is associated with using Tasks in my code. Tasks are a promise for receiving data at some point in the future. I'm pretty certain my Lambda function was exiting before all of the tasks came to fruition. I added the following to force my Lambda to wait until all tasks completed:

...

var futureList = new List<Task>();

foreach (var range in outerRange.TrySplit(_config.HashKeyLength))
{
    var task = RunGeoQuery(geoQueryRequest, geoQueryResult, range, cts.Token);
    taskList.Add(task);
}

Task.WhenAll(taskList).Wait();

...

After adding Task.WhenALl(taskList).Wait(), my Lambda function processed all 24 locations and reflected in CloudWatch logs.

I'm not sure if there are ramifications for using this apporach. Any insights are appreciated.

Thank you.