https://serverless-stack.com/ logo
#help
Title
# help
i

Ian

06/13/2022, 8:14 AM
Hello! I'm having problems using the layers with ESM lambda and I have confirmed that this is an ongoing issue through this twitter post: https://twitter.com/coderbyheart/status/1486470882008645634?s=20&t=Vtq1BPfn1wfM2hc0mpKnDw Now they have a workaround(https://github.com/vibe/aws-esm-modules-layer-support) for this issue and I'm trying to follow the workaround. I was able to create a symlink using the commandHooks. However, I don't know how to add the symlink option during the creation of the zip files.
f

Frank

06/14/2022, 2:49 AM
Hey @Ian, thanks for sharing!
Can u do smth like this?
Copy code
import { execSync} from "child_process";

// creates function.zip
execSync("zip --symlinks -r function.zip .");

// create a layer with function.zip
const layer = new lambda.LayerVersion(this, 'Layer', {
  code: lambda.Code.fromAsset('path/to/function.zip')),
});
i

Ian

06/14/2022, 6:33 AM
Hello @Frank, thanks for the reply. The lambda function is the one that should be zipped with the symlink flag. For reference, in the image below here's what I got when I run "npm run build". The node_modules is the symlink file. Now when I run "npm run deploy", is there an option to add the --symlinks during the zipping of these artifacts? I tried this manually by zipping the artifacts with the symlink flag, then uploading it in my lambda function and the workaround actually works.
Gentle bump @Frank @Jay
j

Jay

06/16/2022, 9:48 PM
@Ian I haven't looked at this before but any idea how you would do this in CDK?
i

Ian

06/17/2022, 3:38 AM
Thank you for the response @Jay I'm new to serverless, so I don't know much about SST and CDK. I'll try to figure it out and let you know if there are any updates. Thanks!
4 Views