Skip to content

Commit 0e16c90

Browse files
authored
docs(lambda): fromAsset exclude (#26473)
We discussed for the need to document `exclude` patterns using a negation in [the PR](#26365 (comment)). I also could not find documentation for the `exclude` property itself, so I added them. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 5eb658b commit 0e16c90

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/aws-cdk-lib/aws-lambda/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,3 +1134,32 @@ new lambda.Function(this, 'Lambda', {
11341134
code: lambda.Code.fromAsset(path.join(__dirname, 'lambda-handler')),
11351135
});
11361136
```
1137+
1138+
## Exclude Patterns for Assets
1139+
1140+
When using `lambda.Code.fromAsset(path)` an `exclude` property allows you to ignore particular files for assets by providing patterns for file paths to exclude. Note that this has no effect on `Assets` bundled using the `bundling` property.
1141+
1142+
The `ignoreMode` property can be used with the `exclude` property to specify the file paths to ignore based on the [.gitignore specification](https://git-scm.com/docs/gitignore) or the [.dockerignore specification](https://docs.docker.com/engine/reference/builder/#dockerignore-file). The default behavior is to ignore file paths based on simple glob patterns.
1143+
1144+
```ts
1145+
new lambda.Function(this, 'Function', {
1146+
code: lambda.Code.fromAsset(path.join(__dirname, 'my-python-handler'), {
1147+
exclude: ['*.ignore'],
1148+
ignoreMode: IgnoreMode.DOCKER, // Default is IgnoreMode.GLOB
1149+
}),
1150+
runtime: lambda.Runtime.PYTHON_3_9,
1151+
handler: 'index.handler',
1152+
});
1153+
```
1154+
1155+
You can also write to include only certain files by using a negation.
1156+
1157+
```ts
1158+
new lambda.Function(this, 'Function', {
1159+
code: lambda.Code.fromAsset(path.join(__dirname, 'my-python-handler'), {
1160+
exclude: ['*', '!index.py'],
1161+
}),
1162+
runtime: lambda.Runtime.PYTHON_3_9,
1163+
handler: 'index.handler',
1164+
});
1165+
```

packages/aws-cdk-lib/rosetta/aws_lambda/default.ts-fixture

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Fixture with packages imported, but nothing else
22
import * as path from 'path';
33
import { Construct } from 'constructs';
4-
import { Aspects, CfnOutput, DockerImage, Duration, RemovalPolicy, Stack } from 'aws-cdk-lib';
4+
import { Aspects, CfnOutput, DockerImage, Duration, IgnoreMode, RemovalPolicy, Stack } from 'aws-cdk-lib';
55
import * as lambda from 'aws-cdk-lib/aws-lambda';
66
import * as iam from 'aws-cdk-lib/aws-iam';
77
import { LAMBDA_RECOGNIZE_VERSION_PROPS, LAMBDA_RECOGNIZE_LAYER_VERSION } from 'aws-cdk-lib/cx-api';

0 commit comments

Comments
 (0)