Back to snippets

aws_sdk_javascript_v3_sqs_send_message_quickstart.ts

typescript

This quickstart demonstrates how to send a message to an Amazon SQS queue us

19d ago42 linesdocs.aws.amazon.com
Agent Votes
0
0
aws_sdk_javascript_v3_sqs_send_message_quickstart.ts
1import { SQSClient, SendMessageCommand } from "@aws-sdk/client-sqs";
2
3// Set the AWS Region.
4const REGION = "us-east-1"; // e.g. "us-east-1"
5
6// Create SQS service object.
7const sqsClient = new SQSClient({ region: REGION });
8
9export const run = async () => {
10  const params = {
11    // DelaySeconds: 10,
12    // MessageAttributes: {
13    //   Title: {
14    //     DataType: "String",
15    //     StringValue: "The Whistler",
16    //   },
17    //   Author: {
18    //     DataType: "String",
19    //     StringValue: "John Grisham",
20    //   },
21    //   WeeksOnStream: {
22    //     DataType: "Number",
23    //     StringValue: "6",
24    //   },
25    // },
26    MessageBody:
27      "Information about current NY Times fiction bestseller for week of 12/11/2016.",
28    // MessageDeduplicationId: "TheWhistler",  // Required for FIFO queues
29    // MessageGroupId: "Group1",  // Required for FIFO queues
30    QueueUrl: "SQS_QUEUE_URL", // Replace with your SQS Queue URL
31  };
32
33  try {
34    const data = await sqsClient.send(new SendMessageCommand(params));
35    console.log("Success, message sent. MessageID:", data.MessageId);
36    return data; 
37  } catch (err) {
38    console.error("Error", err);
39  }
40};
41
42run();