Git Product home page Git Product logo

floydspace / aws-lambda-nodejs-esbuild Goto Github PK

View Code? Open in Web Editor NEW
67.0 6.0 3.0 75 KB

位馃挩 AWS CDK Construct to bundle JavaScript and TypeScript AWS lambdas using extremely fast esbuild.

Home Page: https://floydspace.github.io/aws-lambda-nodejs-esbuild/

License: MIT License

JavaScript 0.16% TypeScript 99.84%
esbuild aws-cdk construct cdk-construct aws lambda bundler typescript aws-lambda-node aws-lambda

aws-lambda-nodejs-esbuild's Introduction

位馃挩 aws-lambda-nodejs-esbuild

AWS CDK Construct to build Node.js AWS lambdas using esbuild.

CDK Construct NodeJS Build Status Coverage Status npm version semantic-release Mentioned in Awesome CDK

Table of Contents

Features

  • Zero-config: Works out of the box without the need to install any other packages
  • Supports ESNext and TypeScript syntax with transforming limitations (See Note)

Note: The default JavaScript syntax target is set to ES2017, so the final bundle will be supported by all AWS Lambda Node.js runtimes. If you still using an old lambda runtime and have to respect it you can play with esbuild target option, see JavaScript syntax support for more details about syntax transform limitations.

Installation

yarn add --dev @aws-cdk/aws-lambda aws-lambda-nodejs-esbuild
# or
npm install -D @aws-cdk/aws-lambda aws-lambda-nodejs-esbuild

Configure

By default, no configuration required, but you can change esbuild behavior:

  import * as cdk from '@aws-cdk/core';
  import { NodejsFunction } from 'aws-lambda-nodejs-esbuild';

  class NewStack extends cdk.Stack {
    constructor(scope, id, props) {
      super(scope, id, props);

      new NodejsFunction(this, 'NewFunction', {
        esbuildOptions: {
          minify: false, // default
          target: 'ES2017',
        }
      });
    }
  }

Check esbuild documentation for the full list of available options. Note that some options like entryPoints or outdir cannot be overwritten. The package specified in the exclude option is passed to esbuild as external, but it is not included in the function bundle either. The default value for this option is ['aws-sdk'].

Usage

The normal AWS CDK deploy procedure will automatically compile with esbuild:

  • Create the AWS CDK project with cdk init app --language=typescript
  • Install aws-lambda-nodejs-esbuild as above
  • Deploy with cdk deploy

See examples: minimal and complete

Author

Victor Korzunin

aws-lambda-nodejs-esbuild's People

Contributors

floydspace avatar masahirompp avatar stephankaag avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

aws-lambda-nodejs-esbuild's Issues

Allow pass-through asset hash

Using a custom asset hash with the Function construct is super useful for saving on some time and resources - if we could pass through the two options to Code.fromAsset (assetHash and assetHashType), that'd be great

Issue with more lambdas on the same level

With structure like:

-root
--XYZ
---lambdas
----lambda1
-----src
------index.ts
----lambda2
-----src
------index.ts

, when trying to deploy both lambdas in same stack like for example:

const lambda1 = new NodejsFunction(this, 'lambda1', {
                runtime: lambda.Runtime.NODEJS_14_X,
                handler: 'XYZ/lambdas/lambda1/src/index.handler',         
                functionName: 'lambda1',
            exclude: [
                'aws-sdk'
            ],
            timeout: cdk.Duration.seconds(5)
        });
const lambda2 = new NodejsFunction(this, 'lambda2', {
                runtime: lambda.Runtime.NODEJS_14_X,
                handler: 'XYZ/lambdas/lambda2/src/index.handler',         
                functionName: 'lambda2',
            exclude: [
                'aws-sdk'
            ],
            timeout: cdk.Duration.seconds(5)
        });

When looking on source code of deployed lambda structure of each function is:

-XYZ
--lambdas
---lambda1
----src
-----index.js
---lambda2
----src
-----index.js

when it should be for lambda1:

-XYZ
--lambdas
---lambda1
----src
-----index.js

and for lambda2:

-XYZ
--lambdas
---lambda2
----src
-----index.js

Can't override exclude of aws-sdk

The list of excluded packages is a union of whatever the user supplies and ['aws-sdk'], which means you can't not exclude aws-sdk.

const exclude = union(props.exclude || [], ['aws-sdk']);

As Lambda doesn't bundle the latest version of the SDK this can be a problem if you depend on a newer SDK version. Ideally in this scenario I'd just bundle aws-sdk until the Lambda version is updated.

cdk synth --no-staging > template.yaml

Hey, when try generate result cdk synth to template.yaml occur an out stranger.

Fetch dependency graph from D:\workspace_aws\cdk-sample-sam\package.json Adding explicit peers for dependency isin-validator Package lock found - Using locked versions Packing external modules: isin-validator@^1.1.1 Package took [5073 ms] Prune: D:\workspace_aws\cdk-sample-sam\.build [3286 ms] Resources: CompleteExampleFunctionServiceRole8C2D7CB0: Type: AWS::IAM::Role Properties: AssumeRolePolicyDocument: Statement: - Action: sts:AssumeRole Effect: Allow Principal: Service: lambda.amazonaws.com

Yarn 2 support

The command currently used by the Yarn packager is yarn install --frozen-lockfile --non-interactive, which isn't compatible with Yarn 2.

For reference, the Yarn 2 command would be yarn install --immutable --immutable-cache.

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.