3
votes

Need your help in understanding some concepts. I have a web application that uses Lambda@Edge on the CloudFront. This lambda function accesses the DynamoDB - making around 10 independent queries. This generates occasional errors, though it works perfectly when I test the lambda function stand alone. I am not able to make much sense out of the cloudfront logs, and Lambda@Edge does not show up in the CloudWatch.

I have a feeling that the DynamoDB queries are the culprit. (because that is all I am doing in the Lambda function) To make sure, I replicated the data over all regions. But that has not solved the problem. I increased the timeout and memory allocated to the lambda function. But that has not helped in any way. But, reducing the number of DB queries seems to help.

Can you please help me understand this? Is it wrong to make DB queries in the Lambda@Edge? Is there a way to get detailed logs of the Lambda@Edge?

2
how does provisioning of your dynamodb table look like?Horatiu Jeflea
Everything is on demand. No provisioning.Vikas

2 Answers

2
votes

Over a year too late, but you never know someone benefits of it. Lambda@Edge does not run in a specific region, hence, if you connect to a DynamoDB table, you need to define the region in which this table can be found.

In NodeJS this would result in the below:

// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set the region 
AWS.config.update({region: 'REGION'});

// Create DynamoDB document client
var docClient = new AWS.DynamoDB.DocumentClient({apiVersion: '2012-08-10'});

As F_SO_K mentioned, you can find your CloudWatch logs in the region closest to you. How to find out which region that would be (in case you're the only one using that specific Lambda@Edge, you can have a look in this documentation)

1
votes

Lambda@Edge logs show up in CloudWatch under the region in which the Lambda was called. I suspect you simply need to go into CloudWatch and change to the correct region to see the logs. If you are calling CloudWatch yourself, this will be the region you are in, not the region you created the Lambda.

Once you have the log you should have much more information to go on.