Hi friends! Having a small problem at the moment a...
# help
a
Hi friends! Having a small problem at the moment and wondering if anyone has any ideas. I'm working on a custom construct as an NPM package, in this construct I need to setup an EC2 instance(due to a persistent connection that needs to be made) To this EC2 instance I need to upload the script that's going to run it. In this npm package I have a lib folder with the script in it. Then I'm using a cdk Asset to upload the script to the EC2 instance. The problem I'm having is with that part, when I import this construct and add it to SST, I get an error during deployment that it
Cannot find asset at ...
It seems that with SST bunding the typescript code of the main app, the package is losing it's __dirname. The code for the asset is:
Copy code
const codeAsset = new Asset(this, "ec2-code-asset", {
      path: path.join(__dirname, "/lib/index.js"),
    });

    // 👇 create the EC2 CloudformationInit data
    const initData = CloudFormationInit.fromElements(
      InitFile.fromExistingAsset("/home/ec2-user/app/index.js", codeAsset)
    );
I'm not quite sure how to fix this, as the asset should be reading the file located within the NPM package I have made here, however it keeps trying to read it from the sst .build directory
f
Hi @ACPixel, is the npm package listed as a dependency in
package.json
? SST shouldn’t be bundling any dependencies https://github.com/serverless-stack/serverless-stack/blob/master/packages/core/src/stacks/build.ts#L17-L24
a
Ah! It's not as it's currently in development and I used npm link for it!
I will add it and see if that helps!
That seems to have done it! Thank you!