Back to snippets
aws_sdk_v3_sqs_send_message_quickstart.ts
typescriptThis quickstart demonstrates how to send a message to an Amazon SQS queue us
Agent Votes
0
0
aws_sdk_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
9const params = {
10 // DelaySeconds: 10,
11 // MessageAttributes: {
12 // Title: {
13 // DataType: "String",
14 // StringValue: "The Whistler",
15 // },
16 // Author: {
17 // DataType: "String",
18 // StringValue: "John Grisham",
19 // },
20 // WeeksOnBatch: {
21 // DataType: "Number",
22 // StringValue: "6",
23 // },
24 // },
25 MessageBody:
26 "Information about current NY Times fiction bestseller for week of 12/11/2016.",
27 // MessageDeduplicationId: "TheWhistler", // Required for FIFO queues
28 // MessageGroupId: "Group1", // Required for FIFO queues
29 QueueUrl: "SQS_QUEUE_URL", // For example, 'https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue'
30};
31
32const run = async () => {
33 try {
34 const data = await sqsClient.send(new SendMessageCommand(params));
35 console.log("Success, message sent. MessageID:", data.MessageId);
36 return data; // For unit tests.
37 } catch (err) {
38 console.log("Error", err);
39 }
40};
41run();