TypeScript and Lambda Serverless Project Limit
Recently, our project deployment met this exception while deploy
An error occurred: DevicePairingUpdatesLambdaFunction - Unzipped size must be smaller than 262144000 bytes (Service: AWSLambda; Status Code: 400; Error Code: InvalidParameterValueException; Request ID:xxxxxxx-11e8-81e6-xxxxxxx).
Look at the limitation for lambda in detail here
https://docs.aws.amazon.com/lambda/latest/dg/limits.html#limits-list
Lambda function deployment package size (compressed .zip/.jar file). 50MB
Size of code/dependencies that you can zip into a deployment package (uncompressed .zip/.jar size). 250
Currently, our projects are packaged and deployed in 2 different ways.
#1 serverless-plugin-typescript plugin
No webpack, no compress map file generated
Run the command >sls package and check the directory .serverless, there will be a zip file, unzip that, the structure will be as follow:
drwxr-xr-x 168 hluo staff 5376 Sep 6 16:36 node_modules
-rw-r--r-- 1 hluo staff 1017 Dec 31 1979 package.json
drwxr-xr-x 6 hluo staff 192 Sep 6 16:37 src
The good part for this plugin is that, all the shared dependencies will be under node_modules, the source codes in src directory are all small
-rw-r--r-- 1 hluo staff 2329 Dec 31 1979 accessToken.js
-rw-r--r-- 1 hluo staff 4686 Dec 31 1979 getVCSettings.js
-rw-r--r-- 1 hluo staff 2208 Dec 31 1979 handler.js
-rw-r--r-- 1 hluo staff 4413 Dec 31 1979 utils.js
So in this case, if you have 20 lambda in this serverless.yaml together, you will have all shared dependencies in node_modules, all lambda codes in src directory.
The bad side for this is that all these javascript files are normal files, no compress.
#2 serverless-webpack plugin
Compress map file generated for each lambda functions
Run the command >sls package and check the directory .serverless, there will be a zip file, unzip that, the structure will be as follow:
-rw-r--r-- 1 hluo staff 4.1M Jan 1 1980 handler.js
-rw-r--r-- 1 hluo staff 5.6M Jan 1 1980 handler.js.map
In this way, there is no node_modules, all related javascript dependencies will be compressed and packaged into the lambda js and js.map files.
The good thing is the files are compressed, so it is smaller than #1 comparing per lambda. But the downside for this plugin is you have no where to share dependencies. So if you have 20 lambda with similar dependencies in one serverless.yaml, you will have 20 bigger js and js.map files, that is why my size get over 50MB.
For example
-rw-r--r-- 1 hluo staff 7.3M Jan 1 1980 deleteDevicePairing.js
-rw-r--r-- 1 hluo staff 10M Jan 1 1980 deleteDevicePairing.js.map
-rw-r--r-- 1 hluo staff 7.3M Jan 1 1980 getPairedDevices.js
-rw-r--r-- 1 hluo staff 10M Jan 1 1980 getPairedDevices.js.map
-rw-r--r-- 1 hluo staff 7.3M Jan 1 1980 updateDevicePairing.js
-rw-r--r-- 1 hluo staff 10M Jan 1 1980 updateDevicePairing.js.map
-rw-r--r-- 1 hluo staff 7.3M Jan 1 1980 updateDeviceSystemName.js
-rw-r--r-- 1 hluo staff 10M Jan 1 1980 updateDeviceSystemName.js.map
I do not know if there are other solutions or plugins, but this is what I found in current situations.
References:
https://docs.aws.amazon.com/lambda/latest/dg/limits.html#limits-list
Recently, our project deployment met this exception while deploy
An error occurred: DevicePairingUpdatesLambdaFunction - Unzipped size must be smaller than 262144000 bytes (Service: AWSLambda; Status Code: 400; Error Code: InvalidParameterValueException; Request ID:xxxxxxx-11e8-81e6-xxxxxxx).
Look at the limitation for lambda in detail here
https://docs.aws.amazon.com/lambda/latest/dg/limits.html#limits-list
Lambda function deployment package size (compressed .zip/.jar file). 50MB
Size of code/dependencies that you can zip into a deployment package (uncompressed .zip/.jar size). 250
Currently, our projects are packaged and deployed in 2 different ways.
#1 serverless-plugin-typescript plugin
No webpack, no compress map file generated
Run the command >sls package and check the directory .serverless, there will be a zip file, unzip that, the structure will be as follow:
drwxr-xr-x 168 hluo staff 5376 Sep 6 16:36 node_modules
-rw-r--r-- 1 hluo staff 1017 Dec 31 1979 package.json
drwxr-xr-x 6 hluo staff 192 Sep 6 16:37 src
The good part for this plugin is that, all the shared dependencies will be under node_modules, the source codes in src directory are all small
-rw-r--r-- 1 hluo staff 2329 Dec 31 1979 accessToken.js
-rw-r--r-- 1 hluo staff 4686 Dec 31 1979 getVCSettings.js
-rw-r--r-- 1 hluo staff 2208 Dec 31 1979 handler.js
-rw-r--r-- 1 hluo staff 4413 Dec 31 1979 utils.js
So in this case, if you have 20 lambda in this serverless.yaml together, you will have all shared dependencies in node_modules, all lambda codes in src directory.
The bad side for this is that all these javascript files are normal files, no compress.
#2 serverless-webpack plugin
Compress map file generated for each lambda functions
Run the command >sls package and check the directory .serverless, there will be a zip file, unzip that, the structure will be as follow:
-rw-r--r-- 1 hluo staff 4.1M Jan 1 1980 handler.js
-rw-r--r-- 1 hluo staff 5.6M Jan 1 1980 handler.js.map
In this way, there is no node_modules, all related javascript dependencies will be compressed and packaged into the lambda js and js.map files.
The good thing is the files are compressed, so it is smaller than #1 comparing per lambda. But the downside for this plugin is you have no where to share dependencies. So if you have 20 lambda with similar dependencies in one serverless.yaml, you will have 20 bigger js and js.map files, that is why my size get over 50MB.
For example
-rw-r--r-- 1 hluo staff 7.3M Jan 1 1980 deleteDevicePairing.js
-rw-r--r-- 1 hluo staff 10M Jan 1 1980 deleteDevicePairing.js.map
-rw-r--r-- 1 hluo staff 7.3M Jan 1 1980 getPairedDevices.js
-rw-r--r-- 1 hluo staff 10M Jan 1 1980 getPairedDevices.js.map
-rw-r--r-- 1 hluo staff 7.3M Jan 1 1980 updateDevicePairing.js
-rw-r--r-- 1 hluo staff 10M Jan 1 1980 updateDevicePairing.js.map
-rw-r--r-- 1 hluo staff 7.3M Jan 1 1980 updateDeviceSystemName.js
-rw-r--r-- 1 hluo staff 10M Jan 1 1980 updateDeviceSystemName.js.map
I do not know if there are other solutions or plugins, but this is what I found in current situations.
References:
https://docs.aws.amazon.com/lambda/latest/dg/limits.html#limits-list