From 720b669175a0af4938b70506d60aca57d82e88c2 Mon Sep 17 00:00:00 2001 From: Christoph Gysin Date: Tue, 31 Mar 2020 22:33:18 +0300 Subject: [PATCH] feat: Support passing AssetOptions fixes #7098 --- packages/@aws-cdk/aws-s3-deployment/README.md | 5 +++++ packages/@aws-cdk/aws-s3-deployment/lib/source.ts | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-s3-deployment/README.md b/packages/@aws-cdk/aws-s3-deployment/README.md index 5b99c88ad8202..7e13e466e51e5 100644 --- a/packages/@aws-cdk/aws-s3-deployment/README.md +++ b/packages/@aws-cdk/aws-s3-deployment/README.md @@ -60,6 +60,11 @@ The following source types are supported for bucket deployments: - Local directory: `s3deploy.Source.asset('/path/to/local/directory')` - Another bucket: `s3deploy.Source.bucket(bucket, zipObjectKey)` +To create a source from a single file, you can pass `AssetOptions` to exclude +all but a single file: + + - Single file: `s3deploy.Source.asset('/path/to/local/directory', { exclude: ['**', '!onlyThisFile.txt'] })` + ## Retain on Delete By default, the contents of the destination bucket will be deleted when the diff --git a/packages/@aws-cdk/aws-s3-deployment/lib/source.ts b/packages/@aws-cdk/aws-s3-deployment/lib/source.ts index 86eae270fcf94..4d50c6de16e36 100644 --- a/packages/@aws-cdk/aws-s3-deployment/lib/source.ts +++ b/packages/@aws-cdk/aws-s3-deployment/lib/source.ts @@ -51,14 +51,17 @@ export class Source { * Uses a local asset as the deployment source. * @param path The path to a local .zip file or a directory */ - public static asset(path: string): ISource { + public static asset(path: string, options?: s3_assets.AssetOptions): ISource { return { bind(context: cdk.Construct): SourceConfig { let id = 1; while (context.node.tryFindChild(`Asset${id}`)) { id++; } - const asset = new s3_assets.Asset(context, `Asset${id}`, { path }); + const asset = new s3_assets.Asset(context, `Asset${id}`, { + path, + ...options, + }); if (!asset.isZipArchive) { throw new Error(`Asset path must be either a .zip file or a directory`); }