Another issue I ran into: When specifying cloudfor...
# help
v
Another issue I ran into: When specifying cloudformation files via
CfnInclude
,
path.join(__dirname, "../../path/to/file")
works When using sst constructs, it respects the baseUrl in
tsconfig.json
, in my case,
./
which is
src
, so
src/path/to/file
works For
experimental.EdgeFunction
,
Code.fromAsset
, seems like it should work the same as
CfnInclude
, but I always get:
Copy code
Error: ENOENT: no such file or directory, copyfile '/Users/***/Projects/***/***/node_modules/@aws-cdk/core/lib/custom-resource-provider/nodejs-entrypoint.js' -> '/Users/***/Projects/***/***/lambdas/.build/lib/edge-function/__entrypoint__.js'
t
The tsconfig base is only respected for
import
functions
It won't be respected for
path.join
v
My directory looks like:
Copy code
lambdas
  ˪ src
  |   ˪ stacks
  |   |   ˪ jobs-distribution
  |   |   |   ˪ my-handler.js
  |   |   |   ˪ jobs-distribution.stack.ts
  |   ˪ index.ts
  ˪ sst.json
  ˪ tsconfig.json
  ˪ package.json
So how will the following work?
Copy code
const location = path.resolve(__dirname, '../../src/stacks/jobs-distribution');
new experimental.EdgeFunction(this, 'jobAccessControl', {
      handler: 'my-handler.handler',
      runtime: Runtime.NODEJS_14_X,
      code: Code.fromAsset(location) // ENOENT
    });
t
I think you should be able to specify your path relative to sst.json
shouldn't need dirname
v
I've tried using
Code.fromAsset('src/stacks/jobs-distribution')
, but I get the same
ENOENT
error. Is there a way to debug this?
t
where is your sst.json?
nvm I see
can you log
console.log(process.cwd())
in your stack code
v
cwd is
lambdas
t
where is your stacks code located?
v
index is in
lambdas/src/stacks
and imports each stack from a subdirectory.
sst.json:
Copy code
{
  "name": "***",
  "region": "us-west-2",
  "main": "src/stacks/index.ts",
  "lint": false,
  "typeCheck": true
}
t
I'm not sure if we support mingling stack code and application code in the same directory like this
v
So far it's worked for every other stack (7 others) except this one.
t
If you
console.log(path.resolve("src/stacks/jobs-distribution"))
what do you get
v
/Users/vrodriguez/Projects/***/***/lambdas/src/stacks/jobs-distribution
t
and that directory definitely exists?
v
yup.
t
can you actually paste the exact error you get when using that
v
Copy code
Error: ENOENT: no such file or directory, copyfile '/Users/vrodriguez/Projects/onica/casa/node_modules/@aws-cdk/core/lib/custom-resource-provider/nodejs-entrypoint.js' -> '/Users/vrodriguez/Projects/onica/casa/lambdas/.build/lib/edge-function/__entrypoint__.js'
    at Object.copyFileSync (node:fs:2800:3)
    at new CustomResourceProvider (/Users/vrodriguez/Projects/onica/casa/node_modules/@aws-cdk/core/lib/custom-resource-provider/custom-resource-provider.ts:86:8)
    at Function.getOrCreateProvider (/Users/vrodriguez/Projects/onica/casa/node_modules/@aws-cdk/core/lib/custom-resource-provider/custom-resource-provider.ts:69:10)
    at Function.getOrCreate (/Users/vrodriguez/Projects/onica/casa/node_modules/@aws-cdk/core/lib/custom-resource-provider/custom-resource-provider.ts:61:17)
    at EdgeFunction.createCrossRegionArnReader (/Users/vrodriguez/Projects/onica/casa/node_modules/@aws-cdk/aws-cloudfront/lib/experimental/edge-function.ts:164:49)
    at EdgeFunction.createCrossRegionFunction (/Users/vrodriguez/Projects/onica/casa/node_modules/@aws-cdk/aws-cloudfront/lib/experimental/edge-function.ts:146:26)
    at new EdgeFunction (/Users/vrodriguez/Projects/onica/casa/node_modules/@aws-cdk/aws-cloudfront/lib/experimental/edge-function.ts:43:14)
    at new JobsDistributionStack (/Users/vrodriguez/Projects/onica/casa/lambdas/src/stacks/jobs-distribution/jobs-distribution.stack.ts:44:30)
    at Object.main (/Users/vrodriguez/Projects/onica/casa/lambdas/src/stacks/index.ts:64:5)
    at Object.<anonymous> (/Users/vrodriguez/Projects/onica/casa/lambdas/.build/run.js:94:16)
t
ah ok this doesn't have anything to do with where your code is. Let me try and remember what this issue is from
are you using yarn?
v
npm
lol I ran into this
Unfortunately wasn't able to resolve, I think this is an issue with the way SST synthesizes the CDK code, it breaks any use of
__dirname
inside cdk
Ah you know what, can you make sure
@aws-cdk/aws-cloudfront
is in you rpackage.json
I think when we build your stacks, if it's not there we bundle it which means it has no access to those static files
v
I think that actually solved the problem. I have a cyclic dependency problem now, but that is much easier to solve.