[@aws-cdk/assets] docs issue - Negate exclude pattern doesn't work
See original GitHub issueI’m unable to use a negated exclude glob to create an asset for a Lambda function with a single source code file.
Reproduction Steps
new Function(this, "DeployAction", {
runtime: Runtime.NODEJS_12_X,
code: new AssetCode(__dirname, {
exclude: ["!deploy.js"]
}),
handler: "deploy.handler",
});
Error Log
No error - the asset ZIP doesn’t respect the negated exclude (it contains deploy.js + the files I was trying to exclude).
The same exclude, but without negation (deploy.js
) does work (deploy.js is excluded from the asset zip).
Environment
- CLI Version : N/A (I don’t have a global CDK installation)
- Framework Version: 1.39.0 (build 5d727c1)
- Node.js Version: v12.13.1
- OS : Mac OS 10.13.6
- Language (Version): TypeScript 3.7.5
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Comments:16 (9 by maintainers)
Top Results From Across the Web
Troubleshooting common AWS CDK issues
This topic describes how to troubleshoot the following issues with the AWS CDK.
Read more >class DockerImageAsset (construct) · AWS CDK
The ignore behavior to use for exclude patterns. invalidation? DockerImageAssetInvalidationOptions, Options to control which parameters are used to invalidate ...
Read more >sam build - AWS Serverless Application Model
To build on your workstation, run this command in the directory containing your SAM template. Built artifacts are written to the .aws-sam/build directory....
Read more >Filter and pattern syntax - Amazon CloudWatch Logs
Filter patterns make up the syntax that metric filters use to match terms in log ... The filter pattern doesn't return the following...
Read more >AWS Cloud Development Kit (AWS CDK) v2 - Developer Guide
Creating the directory and initializing the AWS CDK . ... If pip doesn't work, try replacing it with python -m pip. Version 2....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@danielsharvey We’ve been trying with both
GLOB
andGIT
with almost exactly the same outcomes. We still come up against the issue @Tehnix points out.['*.*', '!*.html']
The closest we’ve come is using that method but with two issues:
REALLY, need some direction here. More than willing to help work thru testing and troubleshooting if anyone has any ideas.
I don’t know if I would say this is necessarily a “docs issue”. The file matching makes it rather difficult to match globs recursively. It’s great that we can use
*.*
to try to match files but not directories, but what happens if you have a folder that has a dot in it? As uncommon as that is, that’s a pretty big caveat to recursive pattern matching.Perhaps you could use a trailing
/
as an indicator that you’re trying to match against directories, and otherwise only match files? So, I could use["*", "!*.html"]
to match only*.html
files recursively; if I did["*/", "!*.html"]
, it would only match*.html
files in the root directory. This way, you could even exclude lists of specific folders:["(folder1|folder2)/"]
The array configuration is misleading, as well. For example, you wouldn’t want to do
["*.*", "!*.html", "!*.css"]
, because it would only ever match*.css
files, since that’s the last one in the array. A couple possibilities that I could see for handling that:shouldExclude()
loop when a negated match is found https://github.com/aws/aws-cdk/blob/cc2600f4f2e43ebe8cc7b57e58e9ed75a210dfc4/packages/%40aws-cdk/core/lib/fs/utils.ts#L18-L29minimatch
is used for glob matching. That way, people know they can do!*(.html|.css)
, or something similar. That still isn’t perfect, but it adds more flexibility, especially if combined with short-circuiting based on negated matches.