0

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?

1 Answer 1

1

The MessageBody property in the input object should be a string, not an object. You can convert your object to a string before passing it to the MessageBody property.

const params = {
        MessageBody: JSON.stringify(messageBody),
        QueueUrl: "https://sqs.us-east-1.amazonaws.com/41111111119/scheduled-userflows"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.