Hello, I am trying to use a Lambda Layer in my Lambda.
Here is my function definition:
export const onUploadHandler = defineFunction({
name: "on-upload-handler",
entry: "./handler.ts",
layers: {
sharp: "arn:aws:lambda:eu-west-1:[ACCOUNT_ID]:layer:sharp:3",
},
});
Following this documentation, I was expecting that I just use import sharp from "sharp" in my Lambda function and then it will use the layer instead of a local installation. If sharp doesn't appear in my ./package.json my deployment fails with the error message: error TS2307: Cannot find module 'sharp' or its corresponding type declarations..
However, when I install sharp locally (even as a dev dependency), it seems to use the local installation which then lets the Lambda invocation fail as my local environment is mac OS and my Lambda runs on Linux.
Here is the invocation error message:
Error: Could not load the "sharp" module using the linux-x64 runtime
Possible solutions:
- Ensure optional dependencies can be installed:
npm install --include=optional sharp
- Ensure your package manager supports multi-platform installation:
See https://sharp.pixelplumbing.com/install#cross-platform
- Add platform-specific dependencies:
npm install --os=linux --cpu=x64 sharp
I don't get my head around it. Any recommendation?
I know I could create a custom resource but then I loose all the benefits of Amplify's integration (e.g., permissions on storage and API resources) which is a pity. Also, I would need to have Docker installed locally, which I want to avoid.