How it works...

In this recipe, we use the serverless-plugin-cloudfront-lambda-edge plugin to associate the authorize function with the CloudFront ApiDistribution. We specify the distribution and the eventType under the lambdaAtEdge element. The plugin then uses this information to create the LambdaFunctionAssociations element on the distribution in the generated CloudFormation template. The eventType can be set to viewer-request, origin-request, origin-response, or view-response. This recipe uses the viewer-request, because it needs access to the authorization header sent by the viewer. We explicitly set the memorySize and timeout for the function, because Lambda@Edge imposes restrictions on these values.

Lambda@Edge records console.log ...

Get JavaScript Cloud Native Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.