Autosave: 2024-11-25 07:19:28

This commit is contained in:
thomasabishop 2024-11-25 07:19:28 +00:00
parent 1f4de4e344
commit 71e841a440
794 changed files with 272 additions and 45 deletions

View file

@ -1,19 +0,0 @@
---
tags: [AWS]
---
# AWS Messaging services
## SNS
> SNS: Simple Notification Service
Similar to SQS but the focus is on notifications rather than messages, i.e
events that fire when something specific happens, not just a message-send event.
It can be used for passing notifications between applications or to persons
through SMS, text, push notifications and email.
**SNS pushes messages out to subscribers while SQS stores the messages until
someone reads them.**
Relation between SNS and SQS - typically paired aren't they.

View file

@ -0,0 +1,42 @@
---
tags: [AWS, SNS, SQS]
created: Monday, November 25, 2024
---
# AWS SNS
The Simple Notification Service is another form of messaging service in AWS,
similar to [SQS](AWS_SQS.md). The key difference is that SNS pushes messages out
to subscribers whereas SQS stores the messages until they are processed.
Before a message can be sent, and SNS topic must exist. One service such as a
lambda will _publish_ to this topic. Another service, will _subscribe_ to the
topic and be alerted when a message is sent to it.
With SNS, one message can be sent to multiple subscribers simultaneously. In
addition there is message filtering at the subscription level so subscribers can
choose to receive only the messages they are interested in.
Many other AWS services can act as SNS subscribers. Some common examples:
- SQS queues
- Lambda functions (trigger on receipt of a message)
- HTTP endpoints
- Email/SMS/Push notifications to mobile apps
## Combining with SQS
Utilising SNS with SQS is a common pattern in serverless applications.
We use SNS to decouple publishers from subscribers and then use SQS to handle
the different subscriber tasks. This is known as the "Fanout-Queue" pattern.
![SQS fanout pattern](static/sns-example.png)
For example, an order is placed which results in a publication event to an SNS
topic.
Multiple systems subscribe to this topic, e.g. an inventory system, a shipping
system and an analytics system.
Each system has its own queue for processing the message.

View file

@ -50,3 +50,8 @@ to the dead letter queue (DLQ) and remove it from the main queue.
If the DLQ reaches a certain threshold this can trigger additional handling such
as raising an Alert in [CloudWatch](./AWS_CloudWatch.md) or other monitoring
tool.
Note that a DLQ is not a distinct entity within the SDK, it is just another SQS
queue that is designated to store failures.
See [AWS SDK Syntax](AWS_SQS_SDK.md).

View file

@ -0,0 +1,85 @@
---
tags: [AWS, SQS]
created: Monday, November 25, 2024
---
# AWS SQS SDK
## Initialising the SQS client
```ts
import { SQSClient } from "@aws-sdk/client-sqs";
const sqs = new SQSClient({ region: "us-east-1" });
```
## Sending a message to the queue
```ts
import { SendMessageCommand } from "@aws-sdk/client-sqs";
const command = new SendMessageCommand({
QueueUrl: queueUrl,
MessageBody: messageBody,
// Optional parameters
DelaySeconds: 0,
MessageAttributes: {
CustomAttribute: {
DataType: "String",
StringValue: "CustomValue",
},
},
});
return await sqs.send(command);
```
## Processing messages on the queue
```ts
import { ReceiveMessageCommand } from "@aws-sdk/client-sqs";
const command = new ReceiveMessageCommand({
QueueUrl: queueUrl,
MaxNumberOfMessages: 10,
WaitTimeSeconds: 20, // Long polling
VisibilityTimeout: 30, // Time other consumers won't see this message
});
const response = await sqs.send(command);
// Then do something
for (const message of response.Messages || []) {
console.log(message);
}
```
## Removing message from queue
```ts
import { DeleteMessageCommand } from "@aws-sdk/client-sqs";
for (const message of response.Messages || []) {
await sqs.send(
new DeleteMessageCommand({
QueueUrl: queueUrl,
ReceiptHandle: message.ReceiptHandle,
}),
);
}
```
## Query a DLQ
```ts
const checkDLQ = async (dlqUrl: string) => {
const command = new GetQueueAttributesCommand({
QueueUrl: dlqUrl,
AttributeNames: ["ApproximateNumberOfMessages"],
});
const response = await sqs.send(command);
return response.Attributes?.ApproximateNumberOfMessages;
};
```

View file

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View file

@ -13,16 +13,17 @@ computer science.
![not-by-ai-badge](static/not-by-ai-alternative--light.svg)
**Build ID:** 6bd22abe-1c26-4082-9ee1-2e98738d9784
**Build ID:** f3ec2d6c-97a4-4a7a-9dfe-64824a6e94ae
**Published:** Sun 24 Nov 2024 10:53:17
**Published:** Mon 25 Nov 2024 07:19:27
### Recent edits
- [[AWS_SNS]]
- [[AWS_SQS]]
- [[AWS_SQS_SDK]]
- [[a771a6d9_attributes_of_internet_enclosure]]
- [[JavaScript_module_types]]
- [[AWS_SQS]]
- [[Messaging_services]]
- [[0716531c_rewilding_the_internet]]
- [[f6564af9_AOL_and_early_internet_enclosure]]
- [[Bauman_quote]]
@ -30,10 +31,9 @@ computer science.
- [[Pacman]]
- [[Passing_arguments_and_options_to_Bash_scripts]]
- [[Functions_in_Bash]]
- [[Bash_file_exists]]
### All notes (498)
### All notes (499)
- [[0716531c_rewilding_the_internet]]
- [[241fe1a3_the_Web_versus_modem_BBSs]]
@ -48,7 +48,9 @@ computer science.
- [[AWS_CLI]]
- [[AWS_CloudWatch]]
- [[AWS_SAM_and_Docker]]
- [[AWS_SNS]]
- [[AWS_SQS]]
- [[AWS_SQS_SDK]]
- [[AWS_architecture_hierarchy]]
- [[Accessing_metadata_about_SQL_database]]
- [[Accessing_secrets_from_a_Lambda]]
@ -305,7 +307,6 @@ computer science.
- [[Memory_addresses]]
- [[Memory_leaks]]
- [[Memory_versus_processor]]
- [[Messaging_services]]
- [[Middleware_in_NodeJS]]
- [[Mixed_and_improper_fractions]]
- [[Modelling_relationships_in_MongoDB]]

View file

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

View file

Before

Width:  |  Height:  |  Size: 145 KiB

After

Width:  |  Height:  |  Size: 145 KiB

View file

Before

Width:  |  Height:  |  Size: 289 KiB

After

Width:  |  Height:  |  Size: 289 KiB

View file

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View file

Before

Width:  |  Height:  |  Size: 6.9 MiB

After

Width:  |  Height:  |  Size: 6.9 MiB

View file

Before

Width:  |  Height:  |  Size: 224 KiB

After

Width:  |  Height:  |  Size: 224 KiB

View file

Before

Width:  |  Height:  |  Size: 6.4 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

View file

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View file

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View file

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View file

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View file

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

Before

Width:  |  Height:  |  Size: 204 KiB

After

Width:  |  Height:  |  Size: 204 KiB

View file

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 49 KiB

View file

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

Before

Width:  |  Height:  |  Size: 165 KiB

After

Width:  |  Height:  |  Size: 165 KiB

View file

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View file

Before

Width:  |  Height:  |  Size: 91 KiB

After

Width:  |  Height:  |  Size: 91 KiB

View file

Before

Width:  |  Height:  |  Size: 133 KiB

After

Width:  |  Height:  |  Size: 133 KiB

View file

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View file

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 45 KiB

View file

Before

Width:  |  Height:  |  Size: 4 KiB

After

Width:  |  Height:  |  Size: 4 KiB

View file

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View file

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View file

Before

Width:  |  Height:  |  Size: 6.3 KiB

After

Width:  |  Height:  |  Size: 6.3 KiB

View file

Before

Width:  |  Height:  |  Size: 2 KiB

After

Width:  |  Height:  |  Size: 2 KiB

View file

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

View file

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

Before

Width:  |  Height:  |  Size: 148 KiB

After

Width:  |  Height:  |  Size: 148 KiB

View file

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View file

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View file

Before

Width:  |  Height:  |  Size: 9.6 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

View file

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View file

Before

Width:  |  Height:  |  Size: 121 KiB

After

Width:  |  Height:  |  Size: 121 KiB

View file

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View file

Before

Width:  |  Height:  |  Size: 470 KiB

After

Width:  |  Height:  |  Size: 470 KiB

View file

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View file

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View file

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View file

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

View file

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 59 KiB

View file

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View file

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View file

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View file

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View file

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 59 KiB

View file

Before

Width:  |  Height:  |  Size: 99 KiB

After

Width:  |  Height:  |  Size: 99 KiB

View file

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View file

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View file

Before

Width:  |  Height:  |  Size: 848 KiB

After

Width:  |  Height:  |  Size: 848 KiB

View file

Before

Width:  |  Height:  |  Size: 194 KiB

After

Width:  |  Height:  |  Size: 194 KiB

View file

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

Before

Width:  |  Height:  |  Size: 130 KiB

After

Width:  |  Height:  |  Size: 130 KiB

View file

Before

Width:  |  Height:  |  Size: 171 KiB

After

Width:  |  Height:  |  Size: 171 KiB

View file

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View file

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View file

Before

Width:  |  Height:  |  Size: 9.7 KiB

After

Width:  |  Height:  |  Size: 9.7 KiB

View file

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View file

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 79 KiB

View file

Before

Width:  |  Height:  |  Size: 157 KiB

After

Width:  |  Height:  |  Size: 157 KiB

View file

Before

Width:  |  Height:  |  Size: 72 KiB

After

Width:  |  Height:  |  Size: 72 KiB

View file

Before

Width:  |  Height:  |  Size: 153 KiB

After

Width:  |  Height:  |  Size: 153 KiB

View file

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

View file

Before

Width:  |  Height:  |  Size: 87 KiB

After

Width:  |  Height:  |  Size: 87 KiB

View file

Before

Width:  |  Height:  |  Size: 118 KiB

After

Width:  |  Height:  |  Size: 118 KiB

View file

Before

Width:  |  Height:  |  Size: 414 KiB

After

Width:  |  Height:  |  Size: 414 KiB

View file

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View file

Before

Width:  |  Height:  |  Size: 174 KiB

After

Width:  |  Height:  |  Size: 174 KiB

View file

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View file

Before

Width:  |  Height:  |  Size: 167 KiB

After

Width:  |  Height:  |  Size: 167 KiB

View file

Before

Width:  |  Height:  |  Size: 150 KiB

After

Width:  |  Height:  |  Size: 150 KiB

View file

Before

Width:  |  Height:  |  Size: 9.2 KiB

After

Width:  |  Height:  |  Size: 9.2 KiB

View file

Before

Width:  |  Height:  |  Size: 140 KiB

After

Width:  |  Height:  |  Size: 140 KiB

View file

Before

Width:  |  Height:  |  Size: 190 KiB

After

Width:  |  Height:  |  Size: 190 KiB

View file

Before

Width:  |  Height:  |  Size: 374 KiB

After

Width:  |  Height:  |  Size: 374 KiB

View file

Before

Width:  |  Height:  |  Size: 9 KiB

After

Width:  |  Height:  |  Size: 9 KiB

View file

Before

Width:  |  Height:  |  Size: 1.2 MiB

After

Width:  |  Height:  |  Size: 1.2 MiB

View file

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 76 KiB

View file

Before

Width:  |  Height:  |  Size: 448 KiB

After

Width:  |  Height:  |  Size: 448 KiB

View file

Before

Width:  |  Height:  |  Size: 122 KiB

After

Width:  |  Height:  |  Size: 122 KiB

View file

Before

Width:  |  Height:  |  Size: 668 KiB

After

Width:  |  Height:  |  Size: 668 KiB

View file

Before

Width:  |  Height:  |  Size: 1.9 KiB

After

Width:  |  Height:  |  Size: 1.9 KiB

View file

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View file

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View file

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View file

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

View file

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB

View file

Before

Width:  |  Height:  |  Size: 108 KiB

After

Width:  |  Height:  |  Size: 108 KiB

View file

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

View file

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

View file

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View file

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View file

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View file

Before

Width:  |  Height:  |  Size: 66 KiB

After

Width:  |  Height:  |  Size: 66 KiB

View file

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

View file

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View file

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

View file

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View file

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View file

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

View file

Before

Width:  |  Height:  |  Size: 3.7 KiB

After

Width:  |  Height:  |  Size: 3.7 KiB

View file

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

View file

Before

Width:  |  Height:  |  Size: 5.8 KiB

After

Width:  |  Height:  |  Size: 5.8 KiB

View file

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

View file

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View file

Before

Width:  |  Height:  |  Size: 7.4 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

View file

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

View file

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 58 KiB

View file

Before

Width:  |  Height:  |  Size: 146 KiB

After

Width:  |  Height:  |  Size: 146 KiB

View file

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View file

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View file

Before

Width:  |  Height:  |  Size: 63 KiB

After

Width:  |  Height:  |  Size: 63 KiB

View file

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View file

Before

Width:  |  Height:  |  Size: 94 KiB

After

Width:  |  Height:  |  Size: 94 KiB

Binary file not shown.

42
zk/AWS_SNS.md Normal file
View file

@ -0,0 +1,42 @@
---
tags: [AWS, SNS, SQS]
created: Monday, November 25, 2024
---
# AWS SNS
The Simple Notification Service is another form of messaging service in AWS,
similar to [SQS](AWS_SQS.md). The key difference is that SNS pushes messages out
to subscribers whereas SQS stores the messages until they are processed.
Before a message can be sent, and SNS topic must exist. One service such as a
lambda will _publish_ to this topic. Another service, will _subscribe_ to the
topic and be alerted when a message is sent to it.
With SNS, one message can be sent to multiple subscribers simultaneously. In
addition there is message filtering at the subscription level so subscribers can
choose to receive only the messages they are interested in.
Many other AWS services can act as SNS subscribers. Some common examples:
- SQS queues
- Lambda functions (trigger on receipt of a message)
- HTTP endpoints
- Email/SMS/Push notifications to mobile apps
## Combining with SQS
Utilising SNS with SQS is a common pattern in serverless applications.
We use SNS to decouple publishers from subscribers and then use SQS to handle
the different subscriber tasks. This is known as the "Fanout-Queue" pattern.
![SQS fanout pattern](../img/sns-example.png)
For example, an order is placed which results in a publication event to an SNS
topic.
Multiple systems subscribe to this topic, e.g. an inventory system, a shipping
system and an analytics system.
Each system has its own queue for processing the message.

View file

@ -50,3 +50,8 @@ to the dead letter queue (DLQ) and remove it from the main queue.
If the DLQ reaches a certain threshold this can trigger additional handling such
as raising an Alert in [CloudWatch](./AWS_CloudWatch.md) or other monitoring
tool.
Note that a DLQ is not a distinct entity within the SDK, it is just another SQS
queue that is designated to store failures.
See [AWS SDK Syntax](AWS_SQS_SDK.md).

85
zk/AWS_SQS_SDK.md Normal file
View file

@ -0,0 +1,85 @@
---
tags: [AWS, SQS]
created: Monday, November 25, 2024
---
# AWS SQS SDK
## Initialising the SQS client
```ts
import { SQSClient } from "@aws-sdk/client-sqs";
const sqs = new SQSClient({ region: "us-east-1" });
```
## Sending a message to the queue
```ts
import { SendMessageCommand } from "@aws-sdk/client-sqs";
const command = new SendMessageCommand({
QueueUrl: queueUrl,
MessageBody: messageBody,
// Optional parameters
DelaySeconds: 0,
MessageAttributes: {
CustomAttribute: {
DataType: "String",
StringValue: "CustomValue",
},
},
});
return await sqs.send(command);
```
## Processing messages on the queue
```ts
import { ReceiveMessageCommand } from "@aws-sdk/client-sqs";
const command = new ReceiveMessageCommand({
QueueUrl: queueUrl,
MaxNumberOfMessages: 10,
WaitTimeSeconds: 20, // Long polling
VisibilityTimeout: 30, // Time other consumers won't see this message
});
const response = await sqs.send(command);
// Then do something
for (const message of response.Messages || []) {
console.log(message);
}
```
## Removing message from queue
```ts
import { DeleteMessageCommand } from "@aws-sdk/client-sqs";
for (const message of response.Messages || []) {
await sqs.send(
new DeleteMessageCommand({
QueueUrl: queueUrl,
ReceiptHandle: message.ReceiptHandle,
}),
);
}
```
## Query a DLQ
```ts
const checkDLQ = async (dlqUrl: string) => {
const command = new GetQueueAttributesCommand({
QueueUrl: dlqUrl,
AttributeNames: ["ApproximateNumberOfMessages"],
});
const response = await sqs.send(command);
return response.Attributes?.ApproximateNumberOfMessages;
};
```

View file

@ -1,19 +0,0 @@
---
tags: [AWS]
---
# AWS Messaging services
## SNS
> SNS: Simple Notification Service
Similar to SQS but the focus is on notifications rather than messages, i.e
events that fire when something specific happens, not just a message-send event.
It can be used for passing notifications between applications or to persons
through SMS, text, push notifications and email.
**SNS pushes messages out to subscribers while SQS stores the messages until
someone reads them.**
Relation between SNS and SQS - typically paired aren't they.