question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[@aws-cdk/assets] docs issue - Negate exclude pattern doesn't work

See original GitHub issue

I’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:open
  • Created 3 years ago
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
iDVBcommented, Jun 11, 2021

@danielsharvey We’ve been trying with both GLOB and GIT 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:

  1. It doesn’t exclude files WITHOUT an extension (files that appear to be like directories since they have no ext)
  2. It leaves all the empty directories intact. Not sure if this would even be an issue or would S3 just ignore since there is no such thing as a directory in s3?

REALLY, need some direction here. More than willing to help work thru testing and troubleshooting if anyone has any ideas.

1reaction
Js-Brechtcommented, Oct 21, 2020

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:

  1. short-circuit the 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-L29
  2. indicate somewhere that minimatch 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.
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found