InvalidLambdaFunctionAssociationException: The function code size is larger than the maximum allowed size

Viewed 2124

While adding a Lambda function association to a CloudFront distribution I'm getting this error

com.amazonaws.services.cloudfront.model.InvalidLambdaFunctionAssociationException: The function code size is larger than the maximum allowed size for functions that are triggered by a CloudFront event: 4283166 Max allowed: 1048576 Function: arn:aws:lambda:us-east-1:xxxxxxx:function:xxxxxxxxx (Service: AmazonCloudFront; Status Code: 400; Error Code: InvalidLambdaFunctionAssociation; Request ID: xxxxx-ee8e-4395-8655-8e49dfaa4765)

enter image description here

1 Answers

The error is quite descriptive: your lambda function is too large to be used for your chosen event trigger (Viewer Request - which has a lower size quota than Origin events, see the table below) on Lambda@Edge.

You need to make your function smaller, or find a way to achieve what you are trying to do another way.

You can find more information in the quotas table in the "Requirements and Restrictions on Lambda Functions" section of the AWS CloudFront documentation. Specifically:

Maximum compressed size of a Lambda function and any included libraries
Origin request and response event quotas: 50 MB
Viewer request and response event quotas: 1 MB

Related