AWS SQS on Lambda throws argument must be ArrayBuffer when sending message using SQSClient

Viewed 15

I am trying to send a message to SQS using a lambda node 16 TypeScript.

If I run it locally the code works. But if I run it externally I get this error:

TypeError: The "input" Received type object ([object Object])

//full message is actually part of the response body: 
//"{\"message\":\"Error: failed to schedule userflow test\\nTypeError: The \\\"input\\\" argument must be ArrayBuffer. Received type object ([object Object])\"}"

The function is quite simple:

import { APIGatewayProxyEvent, APIGatewayProxyResult } from 'aws-lambda';
import { SQSClient, SendMessageCommand } from "@aws-sdk/client-sqs";

export const lambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayProxyResult> => {    
    let response: APIGatewayProxyResult;
    let messageBody: string;

    if (!event.body) {
        response = {
            statusCode: 500,
            body: JSON.stringify({
                message: 'No Target Information Found',
            }),
        };
        return response;
    } else {
        response = {
            statusCode: 200,
            body: JSON.stringify({
                message: 'hello world',
            }),
        };
        messageBody = event.body;
    }

    const client = new SQSClient({ region: "us-east-1" });

    const params = {
        MessageBody: messageBody,
        QueueUrl: "https://sqs.us-east-1.amazonaws.com/41111111119/scheduled-userflows"
    }

    const command = new SendMessageCommand(params);


    try {
        await client.send(command);
    } catch (error) {
        response = {
            statusCode: 500,
            body: JSON.stringify({
                message: 'Error: failed to schedule userflow test\n' + error,
            }),
        };
    } finally {
        return response;
    }
};

What does that mean?

Why does this only happen on Lambda and not locally?

This is with the purpose of achieving this: How can I execute a puppeteer script in the cloud as a single task?

0 Answers
Related