Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@attila.danku/cold-start-tool

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@attila.danku/cold-start-tool

Check your lambdas file size and optimize them to reduce cold start duration.

  • 1.0.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

❄️ Cold start tool ❄️

Introduction:


This tool is designed to analyze built AWS Lambdas. It can check the file size of the Lambdas and, if the build is not minified, it can identify the three most used/imported libraries in the Lambda function and also creates metrics about all of the Lambdas. If the size of the Lambda exceeds a specified threshold, a warning will be generated. Our default config is optimized for SST framework.

About cold start duration

As you can see the larger lambda build size cause a longer cold start duration. Our mission is to reduce the cold start duration and one of the best practices if you reduce your lambda build size.

Lambda build sizeCold start duration
1 MB150 ms
19.6 MB692 ms
30.2 MB1716 ms
52.8 MB2515 ms

Here some examples how to optimize your lambda imports:

// Instead of const AWS = require('aws-sdk'), use:
const DynamoDB = require('aws-sdk/clients/dynamodb')

// Instead of const AWSXRay = require('aws-xray-sdk'), use:
const AWSXRay = require('aws-xray-sdk-core')

// Instead of const AWS = AWSXRay.captureAWS(require('aws-sdk')), use:
const dynamodb = new DynamoDB.DocumentClient()
AWSXRay.captureAWSClient(dynamodb.service)

Usage


Installation:

npm install @theapexlab/cold-start-tool --save-dev

Run:

npm run cst

Uninstall:

npm uninstall @theapexlab/cold-start-tool

Behind the scenes


Upon first run, it creates a cst-config.json with the default settings for SST in the root of the project.

If the lambda is not minified on build time the imported node-modules are commented like this // node_modules/... , so this app basically counts the occurrences of the same imports, and if the file size is over 20MB (can be changed in cst-config.json) the developer gets a warning, and the three most used libs in the lambda.

Configuration


The configuration file cst-config.json can be found at the root of the project. Here you can change a few things:

  • buildPath: default folder where the built lambdas are located
  • searchTerm: the start of the node_module comments to find
  • warningThresholdMB: the maximum acceptable size of the lambda in megabytes
  • showOnlyErrors: show only the files that exceed the warning threshold
  • filterByName: searchfilter for files
  • detailedReport: gives you a detailed report and the end

Custom arguments


Search for something specific in a lambda's name:

npm run cst --filterByName=get

Overwrite the warning threshold:

npm run cst --warningThresholdMB=30

To show only the files that exceed the warning threshold:

npm run cst --showOnlyErrors

To run a detailed report:

npm run cst --detailed-report

To see all available options:

npm run cst --help

Keywords

FAQs

Package last updated on 06 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc