-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Description
It seems that while FollowMode is respected while copying assets to cdk.out, it's not respected when publishing said assets to S3.
A cursory glance at the packaging code shows why this is the case:
aws-cdk/packages/cdk-assets/lib/private/archive.ts
Lines 8 to 16 in dac9bb3
| // The below options are needed to support following symlinks when building zip files: | |
| // - nodir: This will prevent symlinks themselves from being copied into the zip. | |
| // - follow: This will follow symlinks and copy the files within. | |
| const globOptions = { | |
| dot: true, | |
| nodir: true, | |
| follow: true, | |
| cwd: directory, | |
| }; |
Both nodir and follow are hardcoded here and so using FollowMode.NEVER has no effect: symlinks are always followed when uploading to S3.
Reproduction Steps
-
Create a
layerdirectory that contains a file and a relative symlink to that file. -
Create a CDK stack containing:
const layer = new lambda.LayerVersion(stack, 'Layer', {
code: lambda.Code.fromAsset(path.join(__dirname, 'layer'), { follow: assets.FollowMode.NEVER }), // this is the default anyway
});- Deploy the stack.
Observe that in the asset directory in cdk.out, the symlink is preserved as is – it's a relative symlink that points to the file as it was when you created it.
Observe that in the uploaded asset however, the symlink has been followed (ie, the file is duplicated in the layer, there is no symlink anymore). You can either do this by using the layer in a Lambda, or by simply downloading the zipfile asset that was published to S3 and listing its contents.
So there appears to be no way to upload layers (or functions) and preserve symlinks – unless you manually zip them yourselves. Which means FollowMode has no effect.
Environment
- CLI Version : 1.54.0 (build c01b9b9)
- Framework Version: 1.54.0
- Node.js Version: v12.18.0
- OS : macOS
- Language (Version): JavaScript
This is 🐛 Bug Report