Skip to content

Commit

Permalink
feat: add LLRT binary type property (#9)
Browse files Browse the repository at this point in the history
* feat: add LLRT binary type property

* ftfy

* fix
  • Loading branch information
tmokmss authored Sep 19, 2024
1 parent b9e41f7 commit c246e69
Show file tree
Hide file tree
Showing 36 changed files with 3,540 additions and 1,097 deletions.
16 changes: 12 additions & 4 deletions .projen/deps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions .projen/tasks.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions .projenrc.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { join } from 'path';
import { awscdk } from 'projen';
const project = new awscdk.AwsCdkConstructLibrary({
author: 'tmokmss',
authorAddress: '[email protected]',
// we don't strictly guarantee it works in older CDK (integ-runner runs on newer CDK), but hopefully it should.
cdkVersion: '2.38.0',
defaultReleaseBranch: 'main',
jsiiVersion: '~5.3.0',
jsiiVersion: '~5.4.0',
name: 'cdk-lambda-llrt',
projenrcTs: true,
repositoryUrl: 'https://github.com/tmokmss/cdk-lambda-llrt.git',
Expand All @@ -19,10 +21,22 @@ const project = new awscdk.AwsCdkConstructLibrary({
compilerOptions: {},
exclude: ['example', 'test/.*.snapshot'],
},
devDeps: ['@aws-cdk/[email protected]', '@aws-cdk/[email protected]', 'esbuild'],
devDeps: [
'aws-cdk-lib',
'aws-cdk',
'constructs',
'@aws-cdk/integ-runner@^2.159.0-alpha.0',
'@aws-cdk/integ-tests-alpha@^2.159.0-alpha.0',
'esbuild',
],
peerDependencyOptions: {
pinnedDevDependency: false,
},
});

project.addPackageIgnore('.tmp');
// required to run integ tests
project.projectBuild.testTask.exec('npm install', { cwd: join('example', 'lambda') });
project.projectBuild.testTask.exec('yarn tsc -p tsconfig.dev.json && yarn integ-runner');

project.synth();
471 changes: 453 additions & 18 deletions API.md

Large diffs are not rendered by default.

24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ npm install cdk-lambda-llrt
Then you can use `LlrtFunction` construct. Just set an entry point for the function.

```ts
import { LlrtFunction } from 'cdk-lambda-llrt';
import { LlrtFunction, LlrtBundleType } from 'cdk-lambda-llrt';

const handler = new LlrtFunction(this, 'Handler', {
entry: 'lambda/index.ts',
bundleType: LlrtBundleType.FULL_SDK, // Optional: Choose between FULL_SDK, NO_SDK, or STANDARD (default)
});
```

Expand All @@ -28,10 +29,10 @@ If you want to upgrade the LLRT version, remove the `.tmp` directory, which cont

### Setting platform=browser

In some cases, your code may run successfully on LLRT by setting bundle target platform to `browser` (e.g. when using AWS SDK packages that are not bundled in LLRT or packages that can run using Web APIs.) You can configure it by the following code:
In some cases, your code may run successfully on LLRT by setting bundle target platform to `browser`. You can configure it by the following code:

```ts
import { LlrtFunction } from 'cdk-lambda-llrt';
import { LlrtFunction, LlrtBundleType } from 'cdk-lambda-llrt';

const handler = new LlrtFunction(this, 'Handler', {
entry: 'lambda/index.ts',
Expand All @@ -55,5 +56,22 @@ new LlrtFunction(this, 'Handler', {

Note that we enable this flag automatically on Windows platform.

## Bundle Types

LLRT publishes several binaries with different sets of bundled SDKs:

- `LlrtBundleType.FULL_SDK`: Includes all AWS SDKs
- `LlrtBundleType.NO_SDK`: No AWS SDKs included
- `LlrtBundleType.STANDARD`: Standard bundle (default)

You can specify the bundle type when creating a new LlrtFunction:

```ts
const handler = new LlrtFunction(this, 'Handler', {
entry: 'lambda/index.ts',
bundleType: LlrtBundleType.FULL_SDK,
});
```

## Examples
See [example](./example/README.md) for examples to use `LlrtFunction` construct.
16 changes: 15 additions & 1 deletion example/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Stack, StackProps, App } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { LlrtFunction } from '../src/';
import { LlrtBinaryType, LlrtFunction } from '../src/';
import { PolicyStatement } from 'aws-cdk-lib/aws-iam';
import { LambdaIntegration, RestApi } from 'aws-cdk-lib/aws-apigateway';

Expand Down Expand Up @@ -36,11 +36,25 @@ class LlrtFunctionTestStack extends Stack {
);
}

{
const handler = new LlrtFunction(this, 'EcsHandlerFullSdk', {
entry: '../example/lambda/ecs.ts',
llrtBinaryType: LlrtBinaryType.FULL_SDK,
});
handler.addToRolePolicy(
new PolicyStatement({
actions: ['ecs:ListClusters'],
resources: ['*'],
})
);
}

const api = new RestApi(this, 'Api');

{
const handler = new LlrtFunction(this, 'Hono', {
entry: '../example/lambda/hono.ts',
llrtBinaryType: LlrtBinaryType.NO_SDK,
});

api.root.addMethod('GET', new LambdaIntegration(handler));
Expand Down
Loading

0 comments on commit c246e69

Please sign in to comment.