Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(aws-cloudfront): Cannot use Cross-Region edge function with Yarn pnp (Plug N' Play) #19452

Closed
blimmer opened this issue Mar 17, 2022 · 4 comments
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront bug This issue is a bug. p2

Comments

@blimmer
Copy link
Contributor

blimmer commented Mar 17, 2022

What is the problem?

I'm encountering an error when using Yarn Berry (3.2.0) and the default Plug n' Play linker.

Error: EROFS: read-only filesystem, copyfile '/node_modules/aws-cdk-lib/core/lib/custom-resource-provider/nodejs-entrypoint.js -> '/node_modules/aws-cdk-lib/aws-cloudfront/lib/experimental/edge-function/entrypoint.js'

This is the call stack when this exception occurs:

Screen Shot 2022-03-17 at 15 52 42

Interactively debugging shows that the codepath is trying to copy files within the node_modules directory, which PnP explicitly denies:

Screen Shot 2022-03-17 at 15 54 22

Even in the npm / node_modules world, the node_modules directory should likely be treated as read-only to prevent issues between runs.

Reproduction Steps

This stack exposes the problem:

import * as cloudfront from "aws-cdk-lib/aws-cloudfront";
import * as origins from "aws-cdk-lib/aws-cloudfront-origins";
import * as lambda from "aws-cdk-lib/aws-lambda";
import * as s3 from "aws-cdk-lib/aws-s3";
import * as cdk from "aws-cdk-lib";
import { join } from "path";
import { Construct } from "constructs";

export class CdkBugReportsStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, {
      env: {
        region: 'us-west-2',  // This region must be non us-east-1 to show the problem
      },
      ...props
    });

    const bucket = new s3.Bucket(this, "HostingBucket");
    const rootRedirectEdgeFunction = new cloudfront.experimental.EdgeFunction(this, "RootRedirectEdgeFunction", {
      runtime: lambda.Runtime.NODEJS_14_X,
      handler: "root-redirect.handler",
      code: lambda.Code.fromAsset(join(__dirname, "lambda-at-edge")),
    });

    new cloudfront.Distribution(this, "SiteDistribution", {
      defaultBehavior: {
        origin: new origins.S3Origin(bucket),
        edgeLambdas: [
          {
            eventType: cloudfront.LambdaEdgeEventType.VIEWER_REQUEST,
            functionVersion: rootRedirectEdgeFunction.currentVersion,
          },
        ],
      },
    });
  }
}

You can see this issue in my sample repository as well. See blimmer/cdk-bug-reports#1 and https://github.com/blimmer/cdk-bug-reports/runs/5591132734?check_suite_focus=true for the failed synth.

  1. Clone the repo locally git clone -b bug/cloudfront-experimental-with-yarn https://github.com/blimmer/cdk-bug-reports.git
  2. cd cdk-bug-reports
  3. yarn install
  4. yarn cdk synth

What did you expect to happen?

I expected the synth to work without erroring.

What actually happened?

I encounter this error

> yarn cdk synth
/Users/blimmer/code/cdk-bug-reports/.pnp.cjs:6683
  return Object.assign(new Error(`${code}: ${message}`), {code});
                       ^
Error: EROFS: read-only filesystem, copyfile '/node_modules/aws-cdk-lib/core/lib/custom-resource-provider/nodejs-entrypoint.js -> '/node_modules/aws-cdk-lib/aws-cloudfront/lib/experimental/edge-function/__entrypoint__.js'
    at makeError$1 (/Users/blimmer/code/cdk-bug-reports/.pnp.cjs:6683:24)
    at EROFS (/Users/blimmer/code/cdk-bug-reports/.pnp.cjs:6710:10)
    at ZipFS.prepareCopyFile (/Users/blimmer/code/cdk-bug-reports/.pnp.cjs:8419:13)
    at ZipFS.copyFileSync (/Users/blimmer/code/cdk-bug-reports/.pnp.cjs:8410:58)
    at /Users/blimmer/code/cdk-bug-reports/.pnp.cjs:9496:25
    at /Users/blimmer/code/cdk-bug-reports/.pnp.cjs:9724:60
    at ZipOpenFS.getZipSync (/Users/blimmer/code/cdk-bug-reports/.pnp.cjs:9853:14)
    at ZipOpenFS.makeCallSync (/Users/blimmer/code/cdk-bug-reports/.pnp.cjs:9724:17)
    at /Users/blimmer/code/cdk-bug-reports/.pnp.cjs:9490:19
    at /Users/blimmer/code/cdk-bug-reports/.pnp.cjs:9724:60 {
  code: 'EROFS'
}

Subprocess exited with error 1

CDK CLI Version

2.17.0 (build f9cd009)

Framework Version

2.17.0

Node.js Version

16.14.0

OS

macOS 12.3

Language

Typescript

Language Version

TypeScript (3.9.10) | Yarn (3.2.0)

Other information

If I switch the nodeLinker to node-modules, this starts working. However, as mentioned above, we should probably treat the node_modules directory as read-only, as well.

@blimmer blimmer added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 17, 2022
@github-actions github-actions bot added the @aws-cdk/aws-cloudfront Related to Amazon CloudFront label Mar 17, 2022
@ryparker ryparker added the p2 label Mar 17, 2022
@peterwoodworth peterwoodworth removed the needs-triage This issue or PR still needs to be triaged. label Apr 19, 2022
@rix0rrr
Copy link
Contributor

rix0rrr commented May 9, 2022

For now, I'd recommend disabling PnP mode:

nodeLinker: node-modules

@vleandersson
Copy link

+1 on this issue

@blimmer
Copy link
Contributor Author

blimmer commented Apr 6, 2024

I just tried this out with Yarn v4 and the latest CDK and it didn't error. I think the fix for #17460 fixed this.

@blimmer blimmer closed this as completed Apr 6, 2024
Copy link

github-actions bot commented Apr 6, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cloudfront Related to Amazon CloudFront bug This issue is a bug. p2
Projects
None yet
Development

No branches or pull requests

6 participants