简体   繁体   中英

How to Make Console Command Availbable to AWS Lambda Written in Java

I would like to run a piece of Java code in AWS Lambda that calls a shell command (in my case wkhtmltopdf ). I can't seem to figure out how to package the Lambda for this to work:

Cannot run program "wkhtmltopdf": error=2, No such file or directory: java.io.IOException

I've been able to make it work with Node.js. I guess this is due to the "package" being extracted once uploaded whereas with Java the jar stays compressed and thus the executable isn't accessible from java.lang.ProcessBuilder .

I was able to solve this using AWS Lambda Layers . Packagin bin/wkhtmltopdf into a zip file and creating a layer using something along the lines:

aws lambda publish-layer-version --layer-name wkhtmltopdf \
--description "wkhtmltopdf executable" \
--zip-file fileb://$(pwd)/wkhtmltopdf.zip \
--compatible-runtimes java8

After that I was able to select and apply the layer (remember to press save).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM