[assets] symlinks are always followed on publish, FollowMode has no effect
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 83
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: https://github.com/aws/aws-cdk/blob/dac9bb312f5b0a9c83d929c862e30b49f3b8654a/packages/cdk-assets/lib/private/archive.ts#L8-L16
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
1. Create a `layer` directory that contains a file and a relative symlink to that file.
2. Create a CDK stack containing:
```js
const layer = new lambda.LayerVersion(stack, 'Layer', {
code: lambda.Code.fromAsset(path.join(__dirname, 'layer'), { follow: assets.FollowMode.NEVER }), // this is the default anyway
});
```
3. 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: Bug Report
Contributor guide
Research direction
Start by reading packages/cdk-assets/lib/private/archive.ts at the referenced packaging code, then compare the asset in cdk.out with the published S3 zip from the reproduction. Trace how FollowMode.NEVER reaches publishing and verify that the uploaded asset preserves the relative symlink instead of following it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, typescript
- Domain
- cloud, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100