adamfli
adamfli

Reputation: 141

CDK exclude files when deploying lambda

Doing some lambdas in typescript and deploying etc via cdk. All works fine however I am using:

code: lambda.Code.asset('lambdas'),

Where the local dir is lambdas. However this deploys the .js, .ts and .d.ts files within and I am wondering if there was anyway to say something like:

code: lambda.Code.asset('lambdas/*.js'),

And just deploy the javascript files for a smaller deploy etc.

I thought about using the outDir in the tsconfig file but that would also apply to the cdk stack.ts so that won't work.

So any ideas how I can just deploy js files from a ts project?

Upvotes: 6

Views: 7118

Answers (1)

Amit Baranes
Amit Baranes

Reputation: 8122

The key is use fromAsset since asset is deprecated. enter image description here

A bit background about fromAssest:

Behind the scenes, CDK uses the bootstrap stack which creates new Amazon S3. fromAssest Loads the function code from a local disk asset, the directory will be zip archived and then uploaded to bootstrap S3 bucket, then the exact location of the S3 objects will be passed when the stack is deployed.

In order to exclude files use AssetOptions - exclude. fix(assets): support exceptions to exclude patterns #4473.

enter image description here

Usage:

    code: lambda.Code.fromAsset(".", {exclude: ['*.ts']})

Upvotes: 12

Related Questions