Skip to content

Commit

Permalink
feat: Support passing AssetOptions
Browse files Browse the repository at this point in the history
fixes #7098
  • Loading branch information
christophgysin committed Mar 31, 2020
1 parent abc2144 commit 720b669
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/@aws-cdk/aws-s3-deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions packages/@aws-cdk/aws-s3-deployment/lib/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
Expand Down

0 comments on commit 720b669

Please sign in to comment.