Skip to content

Commit 27b8a73

Browse files
committed
docs(docs): prepare documentation and examples
1 parent 3c7fa2f commit 27b8a73

File tree

18 files changed

+167
-5
lines changed

18 files changed

+167
-5
lines changed

README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ Installation
3131
------------
3232

3333
```sh
34-
yarn add --dev aws-lambda-nodejs-esbuild
34+
yarn add --dev @aws-cdk/aws-lambda aws-lambda-nodejs-esbuild
3535
# or
36-
npm install -D aws-lambda-nodejs-esbuild
36+
npm install -D @aws-cdk/aws-lambda aws-lambda-nodejs-esbuild
3737
```
3838

3939

@@ -43,7 +43,21 @@ Configure
4343
By default, no configuration required, but you can change esbuild behavior:
4444

4545
```ts
46-
TODO
46+
import * as cdk from '@aws-cdk/core';
47+
import { NodejsFunction } from 'aws-lambda-nodejs-esbuild';
48+
49+
class NewStack extends cdk.Stack {
50+
constructor(scope, id, props) {
51+
super(scope, id, props);
52+
53+
new NodejsFunction(this, 'NewFunction', {
54+
esbuildOptions: {
55+
minify: false, // default
56+
target: 'ES2017', // default
57+
}
58+
});
59+
}
60+
}
4761
```
4862

4963
Check [esbuild](https://github.com/evanw/esbuild#command-line-usage) documentation for the full list of available options. Note that some options like `entryPoints` or `outdir` cannot be overwritten.
@@ -56,9 +70,11 @@ Usage
5670
The normal AWS CDK deploy procedure will automatically compile with `esbuild`:
5771

5872
- Create the AWS CDK project with `cdk init app --language=typescript`
59-
- Install aws-lambda-nodejs-esbuild plugin as above
73+
- Install `aws-lambda-nodejs-esbuild` as above
6074
- Deploy with `cdk deploy`
6175

76+
See examples: [minimal](examples/minimal/README.md) and [complete](examples/complete/README.md)
77+
6278

6379
Author
6480
------

examples/complete/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# CDK asset staging directory
2+
.cdk.staging
3+
cdk.out
4+
.build

examples/complete/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# [aws-lambda-nodejs-esbuild](../../README.md) complete example
2+
3+
This example shows how to use the `aws-lambda-nodejs-esbuild` construct in the most common way.
4+
5+
Any package set as `external` in the `esbuildOptions` will not be bundled into the output file, but packed as a `node_modules` dependency.
6+
7+
If packing a package is not required, for instance if it exists in a layer, you may set it in the option `exclude`, so it will neither be packed nor bundled. `aws-sdk` is excluded by default.

examples/complete/cdk.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"app": "npx ts-node stack/app.ts",
3+
"versionReporting": false
4+
}

examples/complete/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "complete",
3+
"version": "0.1.0",
4+
"devDependencies": {
5+
"@aws-cdk/aws-lambda": "^1.70.0",
6+
"@aws-cdk/core": "^1.70.0",
7+
"@types/node": "10.17.27",
8+
"aws-cdk": "1.70.0",
9+
"aws-lambda-nodejs-esbuild": "*",
10+
"ts-node": "^8.1.0",
11+
"typescript": "~3.9.7"
12+
},
13+
"dependencies": {
14+
"isin-validator": "^1.1.1"
15+
}
16+
}

examples/complete/src/index.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import validateIsin from 'isin-validator';
2+
3+
export function handler(event: any) {
4+
const isInvalid = validateIsin(event);
5+
6+
return {
7+
statusCode: 200,
8+
body: JSON.stringify({
9+
message: isInvalid ? 'ISIN is invalid!' : 'ISIN is fine!',
10+
input: event,
11+
}),
12+
};
13+
}

examples/complete/stack/app.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import * as cdk from '@aws-cdk/core';
2+
import { CompleteStack } from './stack';
3+
4+
const app = new cdk.App();
5+
new CompleteStack(app, 'CompleteStack');

examples/complete/stack/stack.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as cdk from '@aws-cdk/core';
2+
import { NodejsFunction } from 'aws-lambda-nodejs-esbuild';
3+
4+
export class CompleteStack extends cdk.Stack {
5+
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
6+
super(scope, id, props);
7+
8+
new NodejsFunction(this, 'CompleteExampleFunction', {
9+
handler: 'src/index.handler',
10+
esbuildOptions: {
11+
external: ['isin-validator']
12+
}
13+
});
14+
}
15+
}

examples/complete/tsconfig.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2018",
4+
"module": "commonjs",
5+
"lib": ["es2018"],
6+
"declaration": true,
7+
"strict": true,
8+
"noImplicitAny": true,
9+
"strictNullChecks": true,
10+
"noImplicitThis": true,
11+
"alwaysStrict": true,
12+
"noUnusedLocals": false,
13+
"noUnusedParameters": false,
14+
"noImplicitReturns": true,
15+
"noFallthroughCasesInSwitch": false,
16+
"inlineSourceMap": true,
17+
"inlineSources": true,
18+
"experimentalDecorators": true,
19+
"strictPropertyInitialization": false,
20+
"typeRoots": ["./node_modules/@types"]
21+
},
22+
"exclude": ["cdk.out"]
23+
}

examples/minimal/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# CDK asset staging directory
2+
.cdk.staging
3+
cdk.out
4+
.build

0 commit comments

Comments
 (0)