Giter Site home page Giter Site logo

skyleague / esbuild-lambda Goto Github PK

View Code? Open in Web Editor NEW
2.0 4.0 1.0 957 KB

Simple means of building artifacts that are packageable for deployment to AWS Lambda

Home Page: https://skyleague.io

License: MIT License

JavaScript 1.71% TypeScript 98.29%
aws aws-lambda serverless skyleague typescript

esbuild-lambda's Introduction

ESBuild Lambda (@skyleague/esbuild-lambda)

This tool provides a simple means of building artifacts that are packageable for deployment to AWS Lambda. It works together well with the @skyleague/aws-lambda module for Terraform.

Background

After years of working with a hybrid toolchain of Terraform and the Serverless Framework on the AWS cloud, we felt the need for an agnostic tool for packaging AWS Lambda, that could work with both deployment frameworks. Some projects rely heavily on Terraform, with only a single/few Lambda functions, whereas other projects might opt for a hybrid strategy of deploying "persistent" infra like S3/DynamoDB with the use of standardized Terraform modules, and subsequently deploying the runtime application with the Serverless Framework.

Being able to leverage the same build tool for both types of Lambda deployments helps in unifying the toolchain, making it easy to choose the right type of deployment that best fits the project.

Install

Install esbuild-lambda using npm:

 $ npm install --save-dev @skyleague/esbuild-lambda

Usage

Let's get started with a simple example:

// esbuild.config.ts
import { listLambdaHandlers, esbuildLambda } from '@skyleague/esbuild-lambda'

import path from 'node:path'
import { fileURLToPath } from 'node:url'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

async function main() {
    const handlers = await listLambdaHandlers(path.join(__dirname, 'src', 'functions'))
    await Promise.all(handlers.map((fnDir) => esbuildLambda(fnDir, { root: __dirname })))
}
main().catch((err) => {
    console.error(err)
    process.exit(1)
})

Then add the following script to the package.json section for scripts:

// package.json
{
    "scripts": {
        // add this
        "build": "npx ts-node esbuild.config.ts"
    }
}

Finally, run the build script using npm:

$ npm run build

In this basic configuration, the listLambdaHandlers will search for all the index.ts files with an exported handler function, in the provided directory. Then esbuildLambda will run esbuild on each of those handlers, producing a .build/artifacts folder right next to the index.ts, containing the compiled Typescript handler, as well as a cherry-picked package.json with only the dependencies that are actually encountered in the require/import-chain of the index.ts. The package-lock.json will be copied over from the root of the repository, and the cherry-picked package.json will be installed in the artifact directory using npm ci.

This open source library package is part of the SkyLeague modern application delivery stack.

Support

SkyLeague provides Enterprise Support on this open-source library package at clients across industries. Please get in touch via https://skyleague.io.

If you are not under Enterprise Support, feel free to raise an issue and we'll take a look at it on a best-effort basis!

License & Copyright

This library is licensed under the MIT License (see LICENSE.md for details).

If you using this SDK without Enterprise Support, please note this (partial) MIT license clause:

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND

Copyright (c) 2022, SkyLeague Technologies B.V.. 'SkyLeague' and the astronaut logo are trademarks of SkyLeague Technologies, registered at Chamber of Commerce in The Netherlands under number 86650564.

All product names, logos, brands, trademarks and registered trademarks are property of their respective owners. All company, product and service names used in this website are for identification purposes only. Use of these names, trademarks and brands does not imply endorsement.

esbuild-lambda's People

Contributors

aldegoeij avatar dependabot[bot] avatar eugenpodaru avatar mickvanduijn avatar pevisscher avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

eugenpodaru

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.