Working with Files

In this lesson, you'll have a look at how to work with files when using AWS Lambda.

In Chapter 7, you used a method of the AWS S3 SDK to upload the contents of a string into an S3 bucket. Although you could potentially work with images as in-memory strings or buffers, this would unnecessarily increase the memory footprint of the Lambda function, costing more than it should. The S3 SDK for most languages supports working with file streams.

Our conversion function needs to download an S3 object into a local file so you can later produce thumbnails. It will also need to upload the resulting file contents to S3. You’ll create two utility methods for that. You can save the following code as s3-util.js in the conversion function code directory.

Get hands-on with 1000+ tech skills courses.