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

Update install.md #3235

Merged
merged 6 commits into from
Aug 24, 2022
Merged

Update install.md #3235

merged 6 commits into from
Aug 24, 2022

Conversation

SayefReyadh
Copy link
Contributor

Configuration to deploy AWS Lambda using serverless, esbuild and serverless-esbuild

Configuration to deploy AWS Lambda using serverless, esbuild and serverless-esbuild
@lovell
Copy link
Owner

lovell commented May 22, 2022

Hi, thanks for the PR.

Did you see the existing section about esbuild that provides information about excluding sharp from a build?

https://sharp.pixelplumbing.com/install#esbuild

This section in the sharp docs is more generally about code bunders rather than being specific to deployment, so I'm not sure details of using downstream deployment tools fits here.

Maybe we should add a sentence to the existing Lambda section highlighting that those using a code bundler should read the Bundlers section?

https://sharp.pixelplumbing.com/install#aws-lambda

@SayefReyadh
Copy link
Contributor Author

SayefReyadh commented May 24, 2022

Hi, thanks for the PR.

Did you see the existing section about esbuild that provides information about excluding sharp from a build?

https://sharp.pixelplumbing.com/install#esbuild

This section in the sharp docs is more generally about code bunders rather than being specific to deployment, so I'm not sure details of using downstream deployment tools fits here.

Maybe we should add a sentence to the existing Lambda section highlighting that those using a code bundler should read the Bundlers section?

https://sharp.pixelplumbing.com/install#aws-lambda

Prior to my development, I came across this issue when trying to deploy from my local environment win32-x64 with serverless-esbuild for bundling and serverless deploy and faced similar issues described here #3126. I presume as it tries to bundle the package locally maybe that is why.

  • I will update the PR and move the comments below aws-lambda sections with bundler information as it makes more sense as we are trying to deploy on AWS-Lambda.

On this note, I did try to follow the aws-lambda instructions while local deployment with serverless-esbuild but it was unable to bundle the with sharp-linux-x64.node even if the file contains inside the node_modules. The webpack solution discussed here #2230 helped better understand how to resolve the serverless-esbuild issue.

For automatic deployment, we use CodeBuild from AWS and no other configurations were needed for me.

Copy link
Owner

@lovell lovell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the update, I've left some questions inline.

@@ -230,6 +230,24 @@ SHARP_IGNORE_GLOBAL_LIBVIPS=1 npm install --arch=x64 --platform=linux --libc=gli
To get the best performance select the largest memory available.
A 1536 MB function provides ~12x more CPU time than a 128 MB function.

### serverless-esbuild

To deploy AWS Lambda using serverless framework, esbuild and serverless-esbuild on machines other than Linux x64 (glibc), first ensure sharp is excluded from bundling via the
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does sharp need to be listed under externals on Linux x64 machines too? If so, the wording is a little ambiguous.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need some investigations for this case, if it's required for linux x64 machines as well. So far, in my initial dev deployment, I have configured the following way and it was stable with this configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lovell It does not work if sharp is not put under external with esbuild. Btw, while testing it seems the above setup does not work for v0.30.5.

Currently, I am using v0.30.3 and under the esbuild script tag I have given - npm install --arch=x64 --platform=linux [email protected] to match the version. When I tried to update it with v0.30.5 for both package.json and serverless.yml and run the deployment, the was lambda again started saying something is wrong with the installation "Cannot find module '../build/Release/sharp-linux-x64.node'"

If you have some free time, can you look into this as well. Maybe I am doing something wrong here on my setup. Currently I am using the following versions.

dependencies
    "sharp": "^0.30.3",
    
devDependencies
    "serverless": "^3.16.0",
    "serverless-offline": "^8.4.0",
    "esbuild": "^0.14.38",
    "serverless-esbuild": "^1.26.2",
    "@types/sharp": "^0.30.0",

@SayefReyadh SayefReyadh requested a review from lovell June 7, 2022 06:07
@lovell lovell changed the base branch from main to eagle August 24, 2022 16:36
@lovell lovell merged commit 1bf06bd into lovell:eagle Aug 24, 2022
@lovell
Copy link
Owner

lovell commented Aug 24, 2022

Thank you!

@cauboy
Copy link

cauboy commented Oct 18, 2022

For me the esbuild configuration for serverless-esbuild from the docs didn't work.

After running serverless package the arm file ended up in the node_modules folder of the .zip file.

What worked for me was the following configuration:

# serverless.yml
custom:
  esbuild:
    bundle: true
    external:
      - sharp
    installExtraArgs:
      - '--arch=x64'
      - '--platform=linux'

Version of serverless-esbuild:
"serverless-esbuild": "^1.33.0",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants