Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unzipped size must be smaller than 262144000 bytes - AWS Lambda Error

I have tried to upload my application using servless/lambda function AWS, but i got this issue:

An error occurred: AppLambdaFunction - Unzipped size must be smaller than 262144000 bytes (Service: AWSLambdaInternal; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: 8ea0d887-5743-4db1-96cd-6c5efa57b081).

What is the best way to resolve it?

Look my dependencies:

  "dependencies": {
    "ethereumjs-tx": "^1.3.7",
    "aws-sdk": "^2.4.52",
    "body-parser": "^1.18.3",
    "compression": "^1.7.4",
    "consign": "^0.1.6",
    "cors": "^2.8.5",
    "express": "^4.16.4",
    "helmet": "^3.16.0",
    "moment": "^2.24.0",
    "openzeppelin-solidity": "^2.3.0",
    "serverless": "^1.48.2",
    "serverless-http": "^1.9.1",
    "serverless-offline": "^4.9.4",
    "truffle": "^5.1.9",
    "truffle-hdwallet-provider": "^1.0.17",
    "web3": "^1.2.5-rc.0"
  },

Serverless.yml:

provider:
  name: aws
  runtime: nodejs8.10
  stage: v1
  region: us-east-1
  timeout: 30
  memorySize: 512
  package:
    excludeDevDependencies: true
    exclude:
      - .git/**
      - .vscode/**        
      - venv/**

functions:
  app:  
    handler: handler.run
    events:
      - http:
          path: /
          method: ANY
          cors: true
      - http:
          path: /{proxy+}
          method: ANY
          cors: true

plugins:
  - serverless-offline  
like image 578
Danilo Avatar asked Jan 27 '20 13:01

Danilo


2 Answers

Use the directive exclude at your serverless.yml file. In case of Python, I've been used it as follows:

package:
  exclude:
    - node_modules/**
    - venv/**

The build process will exclude them from the build before sending to AWS.

Tip I got in this issue at Github. The documentation for this directive is detailed here.

like image 130
Adriano Laranjeira Avatar answered Oct 05 '22 04:10

Adriano Laranjeira


You can use module bundlers to package the code.

Using module bundlers such as webpack

You can consider using plugins like serverless-webpack. The serverless-webpack plugin is using webpack to build the project and it will only include the bare minimum files required to run your application. It will not include the entire node_modules directory. so that your deployment package will be smaller.

a note about using of Lambda layers

Like others mentioned, you can use the layers and move some of the libraries and code to the layer. Layers are mainly used to share code between functions. The unzipped deployed package including layers cannot exceed 250MB.

hope this helps.

References:

https://github.com/serverless-heaven/serverless-webpack

https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html#configuration-layers-path

like image 38
Arun Kamalanathan Avatar answered Oct 05 '22 02:10

Arun Kamalanathan