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

works locally, but on Lambda getting "params.Body is required" error #840

Open
mkantautas opened this issue Nov 27, 2021 · 1 comment
Open

Comments

@mkantautas
Copy link

Nodejs 12.x

Using this lamda function to convert from heic to jpg and store to my s3 bucket.
works locally, but on Lambda getting "params.Body is required" error

"use strict";
const gm = require('gm').subClass({imageMagick: true});

const root = process.env['LAMBDA_TASK_ROOT'];
const path = process.env['PATH'];
const libPath = process.env['PATH'];
var AWS = require('aws-sdk');
var s3 = new AWS.S3();
// change the Lambda Runtime to use pre-built binary
process.env['PATH'] = `${root}/bin:${path}`;
process.env['LD_LIBRARY_PATH'] = `${root}/lib:${libPath}`;

// convert HEIC to JPEG
module.exports.handler = async (event, context, callback) => {
    let from = event.source_img_path;
    let to = event.destination_img_path
    let thumbnail = event.thumbnail
    // main
    let image = gm(from)
        .noProfile()

    if (thumbnail) {
        image = image.resize("128^", "128^")
            .crop(128, 128)
    }

    image.toBuffer('jpg', function (err, buffer) {
        let params = {Bucket: process.env.BUCKET_NAME, Key: to, Body: buffer};
        new Promise(resolve => {
            s3.upload(params, function (err, result) {
                if (err) {
                    console.log(err)
                    throw new Error('Could not upload photo');
                } else {
                    console.log(result)
                    resolve(result);
                }
            })
        })
    })
};


Does anyone know how to resolve this? Or the issue is that you can't use 'toBuffer' on Lambda? Thanks in advance.

@1001Josias
Copy link

Add an imagemagick layer in lambda?

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

No branches or pull requests

2 participants