1

Creating an origin request lambda@edge to intercept cloudfront events. Every example I can see in the aws docs https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-examples.html refers to the event as

const request = event.Records[0].cf.request;

can the events be batched? unsure if I have to parse the whole array of records. Can't find a definitive answer in the docs

tmc
  • 404
  • 1
  • 7
  • 20

1 Answers1

1

There's no need to worry about parsing the array as there will always be only a single record per event.

The array of Records is there so that messages from different services have a similar structure (e.g. SQS, which potentially delivers messages in batches, and CloudFront or SNS, which don't).

Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
  • thank you! any documentation to support that? – tmc Aug 04 '23 at 13:58
  • Nothing specific as far as I know. However, in HTTP each request is singular and it wouldn't make any sense for CloudFront to aggregate multiple requests into a batch. – Dennis Traub Aug 04 '23 at 14:52
  • 1
    This can also be implicitly derived from this documentation page: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/lambda-cloudfront-trigger-events.html "The function executes when CloudFront receives _a_ request ...", "The function executes after CloudFront receives _a_ response", etc. Note the singular "a" in each of the sentences. It triggers for every single event that occurs, which means there can't be multiple events captured by one trigger. – Dennis Traub Aug 04 '23 at 14:55