I get this error RequestEntityTooLargeException: Request must be smaller than 70167211 bytes for the CreateFunction operation
TypeScriptThe
RequestEntityTooLargeException: Request must be smaller than 70167211 bytes for the CreateFunction operation
error indicates that the deployment package you are trying to upload to AWS Lambda is too large. AWS Lambda has a limit for the size of deployment packages that can be uploaded directly.To resolve this issue, you can do the following:
- Reduce the size of your deployment package by removing unnecessary files or dependencies.
- Use Amazon S3 to host larger deployment packages and reference them in your Lambda function configuration.
Below is a Pulumi program that demonstrates how to create a Lambda function with a deployment package stored in an S3 bucket, assuming that you've already uploaded a zipped file to S3:
import * as aws from "@pulumi/aws"; // Create an IAM role that AWS Lambda can assume const lambdaRole = new aws.iam.Role("lambdaRole", { assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ Service: "lambda.amazonaws.com", }), }); // Attach the AWSLambdaBasicExecutionRole policy to the IAM role const lambdaRolePolicyAttachment = new aws.iam.RolePolicyAttachment("lambdaRolePolicyAttachment", { role: lambdaRole, policyArn: "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", }); // Create an S3 bucket to store the zipped file if you don't have one already const bucket = new aws.s3.Bucket("lambdaBucket", { acl: "private", }); // Upload the zipped file to S3 (example, normally done outside Pulumi) const lambdaZip = new aws.s3.BucketObject("lambdaZip", { bucket: bucket, source: new pulumi.asset.FileAsset("./path-to-your-lambda-deployment-package.zip"), }); // Create a Lambda function and reference the S3 bucket and the uploaded zipped file const lambdaFunction = new aws.lambda.Function("myLambdaFunction", { code: { s3Bucket: bucket.bucket, s3Key: lambdaZip.key, }, role: lambdaRole.arn, handler: "index.handler", // This is an example; adjust based on your handler. runtime: aws.lambda.NodeJS12dXRuntime, // Select the runtime accordingly. }); // Export the name of the bucket and the ARN of the Lambda function export const bucketName = bucket.bucket; export const lambdaFunctionArn = lambdaFunction.arn;
Make sure to replace the
"./path-to-your-lambda-deployment-package.zip"
with the actual path to your zipped Lambda deployment package and adjust the handler and runtime properties according to your function's configuration.