Invoking System Utilities

Here, you'll learn how to invoke system utilities!

We'll cover the following

child_process #

Now that mogrify is available to your Lambda function, you can change the source code for the conversion function to execute it.

To start a command-line utility from JavaScript, you’ll need to use the Node.js child process features.

The spawn function from the Node.js child_process module uses callbacks. You need to wrap that function into a Promise, so it can be used directly in async functions. (This is a limitation of Node.js, so if you are using a different language, the whole issue with multiple types of asynchronous processes does not apply.) Another file is added to your image-conversion function directory and is called child-process-promise.js. The file should contain the following listing, which is a relatively generic function that will create a sub-process to invoke an external command and print out any console output into the logs so you can troubleshoot more easily.

Get hands-on with 1200+ tech skills courses.