0.2.47 • Published 2 years ago

@wheatstalk/cdk-lambda-pnp v0.2.47

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

GitHub Workflow Status npm construct hub link

CDK Lambda PnP Functions

This CDK library allows you to bundle and deploy your AWS Lambda functions from a Yarn PnP project. This project emphasizes using the PnP runtime inside the Lambda environment without single-file bundling.

Features

  • Bundles yarn workspaces and their dependencies so that you can use Yarn PnP in AWS Lambda.
  • Smaller node dependency file sizes due to PnP compression
  • First-class support for yarn workspaces focus and yarn.BUILD
  • CDK hotswap compatibility to speed up your inner loop
  • Allows you to group related lambda handlers into fewer assets to reduce asset publishing time
  • Bring-your-own typescript compiler (works with tsc, esbuild, and swc.)
  • Supports cross-workspace module resolution
  • Supports hard-to-bundle packages if yarn PnP supports them

Yarn Workspace Function

YarnWorkspaceFunction provides a basic lambda function from a yarn workspace. Your compiled code and dependencies are staged and trimmed down using yarn's workspace-tools plugin and yarn workspaces focus command.

const handler = new YarnWorkspaceFunction(scope, 'Handler', {
  // Specify the yarn workspace package name
  workspace: 'lambda',
  // Specify the workspace-relative file containing the lambda handler
  handler: 'dist/api.handler',
  // Optionally specify where to find the yarn project
  projectPath: optionalYarnProjectDir,
});

// Use your function in an API, for example
const httpApi = new apigatewayv2.HttpApi(scope, 'HttpApi', {
  defaultIntegration: new apigatewayv2_integrations.LambdaProxyIntegration({
    handler,
  }),
});

Excluding files

To exclude files from the lambda code bundle, add standard .npmignore files to your packages. It is generally recommended to include a .npmignore in the package that synthesizes your cdk.out cloud assembly to avoid bundling the cdk.out directory.

Example project structure:

.
├── package.json
├── ...
└── packages
    ├── api
    │   ├── package.json
    │   └── ...
    └── cdk
        ├── package.json
        ├── .npmignore
        ├── ...
        └── cdk.out <.npmignored>
            └── ... <.npmignored>

Use yarn.BUILD

The YarnBuildFunction construct provides a more robust out-of-the-box experience through the yarn.BUILD yarn plugin. In addition to bundling code from a yarn workspace, this construct allows you to run yarn.BUILD's build command during construct synthesis. This build command will automatically build your workspace and all workspace dependencies.

const handler = new YarnBuildFunction(scope, 'Handler', {
  // Specify the yarn workspace package name
  workspace: 'lambda',
  // Specify the workspace-relative path containing the lambda handler
  handler: 'dist/api.handler',
  // Optionally run 'yarn install'.
  runInstall: true,
  // Optionally run 'yarn workspace lambda build'.
  runBuild: true,
  // Optionally specify where to find the yarn project
  projectPath: optionalYarnProjectDir,
});

// Use your function in an API, for example
const httpApi = new apigatewayv2.HttpApi(scope, 'HttpApi', {
  defaultIntegration: new apigatewayv2_integrations.LambdaProxyIntegration({
    handler,
  }),
});
0.2.47

2 years ago

0.2.46

2 years ago

0.2.45

2 years ago

0.2.44

2 years ago

0.2.43

2 years ago

0.2.42

2 years ago

0.2.41

2 years ago

0.2.40

2 years ago

0.2.39

2 years ago

0.2.38

2 years ago

0.2.37

2 years ago

0.2.36

2 years ago

0.2.35

2 years ago

0.2.34

2 years ago

0.2.33

2 years ago

0.2.32

2 years ago

0.2.31

2 years ago

0.2.30

2 years ago

0.2.29

2 years ago

0.2.28

2 years ago

0.2.27

2 years ago

0.2.26

2 years ago

0.2.25

2 years ago

0.2.24

2 years ago

0.2.23

2 years ago

0.2.22

2 years ago

0.2.21

2 years ago

0.2.20

3 years ago

0.2.19

3 years ago

0.2.18

3 years ago

0.2.17

3 years ago

0.2.16

3 years ago

0.2.15

3 years ago

0.2.14

3 years ago

0.2.13

3 years ago

0.2.12

3 years ago

0.2.11

3 years ago

0.2.10

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

0.0.0

3 years ago