Skip to content

[assets] symlinks are always followed on publish, FollowMode has no effect #9251

@mhart

Description

@mhart

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:

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

  1. Create a layer directory that contains a file and a relative symlink to that file.

  2. 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
});
  1. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/assetsRelated to the @aws-cdk/assets packagebugThis issue is a bug.effort/smallSmall work item – less than a day of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions