Tutorial / Cram Notes

Amazon SNS is a fully managed messaging service designed for high-throughput, push-based, many-to-many messaging. It allows you to decouple microservices, distributed systems, and serverless applications using publish/subscribe model. With SNS, you can fan out messages to a large number of subscriber endpoints for parallel processing, including Amazon SQS queues, AWS Lambda functions, HTTP/S webhooks, SMS messages, and email addresses.

Key Features of Amazon SNS:

  • Topics: A publisher sends messages to a topic, which is a logical access point and communication channel.
  • Subscriptions: Subscribers receive messages from topics they are subscribed to.
  • Message Filtering: SNS allows filtering messages sent to endpoints so a subscriber receives only the messages it needs.

Amazon SNS Example:

  • Notifications system for a new upload in a file storage application.
  • When a new file is uploaded, the application publishes a message to an SNS topic.
  • Various systems are subscribed to the topic, like a thumbnail generator which is an AWS Lambda function, an SQS queue for metadata extraction, and an email notification service.

Amazon Simple Queue Service (Amazon SQS)

Amazon SQS is a fully managed message queuing service that enables you to decouple and scale microservices, distributed systems, and serverless applications. It provides a robust, secure, and highly scalable way to manage message queues for smooth data transfer between different components of an application.

Key Features of Amazon SQS:

  • Standard Queues: Offers maximum throughput, best-effort ordering, and at-least-once delivery.
  • FIFO Queues: Provides first-in-first-out delivery and exactly-once processing capabilities.

Amazon SQS Example:

  • Order processing system where orders are sent to an SQS queue from where they are consumed by an order processing microservice.
  • As new orders arrive, they are stored in the queue and then asynchronously processed in a scalable, failure-resistant manner.

AWS Step Functions

AWS Step Functions is a serverless orchestration service that enables you to combine AWS services into serverless workflows. You can design and run workflows that stitch together services like AWS Lambda and Amazon ECS into feature-rich applications.

Key Features of AWS Step Functions:

  • Visual Workflows: Step Functions provides a visual interface to model the steps of your workflow.
  • Serverless: It is fully managed which means no infrastructure to manage.
  • Error Handling: It has built-in error handling, retry logic, and state management.

AWS Step Functions Example:

  • An e-commerce order fulfillment process where Step Functions coordinate multiple AWS services.
  • A Step Functions state machine defines tasks like order validation, inventory check, payment processing, and shipping.
  • Each task is implemented as a Lambda function or interacts with other AWS services like Amazon S3 or DynamoDB.

Comparing Amazon SNS, Amazon SQS, and AWS Step Functions

Feature Amazon SNS Amazon SQS AWS Step Functions
Communication Style Publish/Subscribe (Pub/Sub) Message Queuing Workflow Orchestration
Scaling Automatic Scalability Automatic Scalability Automatic Scalability
Ordering No specific order FIFO Queues guarantee order Ordered based on defined workflow
Delivery Style Push (messages are pushed to clients) Pull (messages are pulled by clients) Managed (workflow steps are executed)
Use Case Fan-out message to multiple receivers Decoupling components with queueing Orchestrating microservices

Integration of these services can significantly simplify the architecture of cloud applications. For example, you might use Amazon SNS to broadcast high-volume messages to multiple recipients such as Amazon SQS queues, where they can be processed individually. Further down the workflow, AWS Step Functions could then be used to coordinate more complex multi-step operations based on messages processed by consumers.

Each AWS service is tailored to fit specific integration patterns and use cases, and a well-architected solution will often leverage a combination of these services to build resilient, scalable, and maintainable architectures. Aspiring AWS Certified Solutions Architect – Professional candidates should thoroughly understand these services, their use cases, and best practices to design and implement advanced cloud-based solutions.

Practice Test with Explanation

True/False: Amazon SNS allows you to send messages to a large number of subscribers, including Amazon SQS queues and AWS Lambda functions.

Answer: True

Explanation: Amazon Simple Notification Service (SNS) is a highly available, durable, secure, fully managed pub/sub messaging service that enables you to decouple microservices, distributed systems, and serverless applications.

Multiple select: Which of the following are features of Amazon SQS? (Select all that apply)

  • a) Unlimited Throughput
  • b) At-least-once delivery
  • c) First-in, first-out (FIFO) queues
  • d) Delayed delivery

Answer: a) Unlimited Throughput, b) At-least-once delivery, c) First-in, first-out (FIFO) queues, d) Delayed delivery

Explanation: Amazon SQS supports unlimited throughput, at-least-once delivery, FIFO queues to ensure messages are processed in order, and the ability to delay the delivery of messages.

True/False: AWS Step Functions can only integrate with AWS services and cannot interact with any external services or APIs.

Answer: False

Explanation: AWS Step Functions can coordinate components of distributed applications and microservices using visual workflows. It can interact with AWS services, external services, and any public HTTP endpoints.

Single select: What type of message filtering is provided by Amazon SNS?

  • a) Content-based filtering
  • b) Time-based filtering
  • c) Subscriber-based filtering
  • d) No message filtering is available

Answer: a) Content-based filtering

Explanation: Amazon SNS provides content-based message filtering to send messages to subscribers that only match specific criteria, thereby reducing message traffic to applications that do not need certain messages.

Single select: Which of the following is a benefit of using Amazon SQS?

  • a) Synchronous replication across regions
  • b) Automatic message encryption
  • c) Reduced message delivery latency
  • d) In-memory caching of messages

Answer: b) Automatic message encryption

Explanation: Amazon SQS encrypts messages at rest automatically, which secures them until they can be retrieved and decrypted by the intended recipient.

True/False: AWS Step Functions can directly invoke functions deployed on AWS Lambda without requiring additional services.

Answer: True

Explanation: AWS Step Functions can directly invoke AWS Lambda functions, enabling you to build serverless workflows that include function orchestration.

Multiple select: Which of the following AWS services can be targets for Amazon SNS notifications? (Select all that apply)

  • a) Amazon Kinesis Data Firehose
  • b) Amazon RDS
  • c) Amazon SQS
  • d) AWS Lambda

Answer: a) Amazon Kinesis Data Firehose, c) Amazon SQS, d) AWS Lambda

Explanation: Amazon SNS can publish messages to Amazon Kinesis Data Firehose, Amazon SQS queues, and AWS Lambda functions among other services. It does not have direct integration to publish messages to Amazon RDS.

Single select: What does the “dead-letter queue” feature in Amazon SQS provide?

  • a) Priority queueing of messages
  • b) Temporary storage of undeliverable messages
  • c) A queue for delayed messages
  • d) A logging mechanism for all message transactions

Answer: b) Temporary storage of undeliverable messages

Explanation: The dead-letter queue feature in Amazon SQS is used to store messages that cannot be delivered successfully to the receiving component after several attempts.

True/False: Messages in Amazon SNS are deleted immediately after they have been successfully published to all subscribers.

Answer: True

Explanation: Once a message is successfully delivered to all subscribers or the message retention period has expired, the message is deleted from Amazon SNS.

Single select: What is the maximum retention period for messages in Amazon SQS?

  • a) 14 days
  • b) 7 days
  • c) 4 days
  • d) 30 seconds

Answer: a) 14 days

Explanation: Amazon SQS allows you to retain messages in a queue for up to 14 days.

True/False: Amazon SNS supports message ordering, ensuring that subscribers receive messages in the exact order they were sent.

Answer: False

Explanation: Amazon SNS offers a pub/sub messaging paradigm and does not guarantee message ordering. Amazon SQS FIFO (First-In-First-Out) queues, on the other hand, do guarantee ordering.

Single select: Which of the following features is NOT provided by AWS Step Functions?

  • a) Visual interface to model workflows
  • b) Real-time auditing of each step in the workflow
  • c) Automatic execution of workflows based on machine learning
  • d) Handling of workflow execution in case of errors

Answer: c) Automatic execution of workflows based on machine learning

Explanation: AWS Step Functions provides a visual interface to model workflows, allows for the tracking of each step in real-time, and facilitates error handling, but it does not have an inherent feature for automatically executing workflows based on machine learning.

Interview Questions

What is Amazon SNS and how does it differ from Amazon SQS in the context of application integration?

Amazon SNS is a fully managed messaging service for both application-to-application (A2A) and application-to-person (A2P) communication. It allows for the sending of messages to subscribing endpoints or clients. Amazon SQS, on the other hand, is a message queuing service that enables decoupling of components in a distributed system. The main difference is that SNS follows a publish-subscribe model, allowing multiple subscribers for a topic, while SQS follows a queue model, where messages are delivered to one consumer at a time and require polling.

Can you describe a scenario where AWS Step Functions would be preferable to using Amazon SNS or Amazon SQS?

AWS Step Functions is ideal for orchestrating multiple AWS services in a serverless workflow. A scenario in which Step Functions would be preferable is during a complex business process that requires several steps, coordination, and state management. For example, an order processing workflow that involves functions like inventory check, payment processing, and shipment could be managed as a state machine in Step Functions.

How would you implement a system in AWS to ensure at-least-once delivery semantics for messages?

To ensure at-least-once delivery, you can use Amazon SQS, which guarantees that a message is delivered at least once. Additionally, using message deduplication IDs and visibility timeouts can help manage the processing of messages without losing any due to failure or retries.

How do you secure sensitive data within messages in Amazon SNS or SQS?

For securing sensitive data within messages, you would use Server-Side Encryption (SSE) for Amazon SNS and Amazon SQS. This involves configuring the services to use AWS Key Management Service (KMS) keys for encrypting messages at rest. For data in transit, both services use HTTPS endpoints to secure data moving between clients and the service.

How can you handle message processing failures in AWS SQS?

To handle message processing failures in AWS SQS, you can leverage features such as Dead Letter Queues (DLQs) where messages that cannot be processed successfully after several attempts are moved to a DLQ. There, they can be analyzed and retried manually or programmatically.

How do Amazon SNS and Amazon SQS integrate with AWS Lambda, and when would you use each service with Lambda?

Amazon SNS and AWS Lambda can integrate by triggering a Lambda function to process messages sent to a topic. Amazon SQS can also trigger Lambda to process messages from a queue. The choice of service depends on use-case. SNS is suitable for fanout scenarios to trigger multiple functions, while SQS is suitable for decoupling system components and regulating workloads.

What is the default message retention period in Amazon SQS, and how can it be changed?

The default message retention period in Amazon SQS is 4 days. This can be changed by setting the “Message Retention Period” attribute on a queue, which can range from a minimum of 1 minute to a maximum of 14 days.

In what scenario would you choose to use a FIFO (First-In-First-Out) queue over a standard queue in Amazon SQS, and why?

A FIFO queue would be chosen over a standard queue when the order of operations and events is critical. FIFO queues guarantee that messages are processed exactly once, in the exact order in which they are sent. This is essential for tasks that are sensitive to the sequence of messages, such as bank transactions.

How would you monitor the performance of Amazon SNS and Amazon SQS?

Monitoring can be achieved using Amazon CloudWatch, which provides metrics for monitoring the performance of both Amazon SNS and Amazon SQS. Key metrics include the number of messages sent, delivered, and failed for SNS, and the number of messages received, sent, deleted, and the queue size for SQS.

During an AWS architecture review, you recognize that an application uses Amazon SNS to deliver notifications immediately. However, this causes some messages to be missed during peak times. What is a potential solution to ensure message delivery without delay?

To alleviate the issue of missed messages during peak times, implementing Amazon SQS in conjunction with Amazon SNS might be recommended. By creating an SNS topic that forwards messages to an SQS queue, applications can pull the messages at their own pace, ensuring no messages are missed even during times of high throughput. This also provides an added benefit of message storage, allowing for delayed processing.

0 0 votes
Article Rating
Subscribe
Notify of
guest
23 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Kiara Faure
3 months ago

Great breakdown on AWS Step Functions! This really clarified the orchestration process for me.

Rosinalva das Neves
4 months ago

Thanks for explaining the differences between Amazon SNS and SQS. It was quite insightful.

Pedro Contreras
3 months ago

Can anyone clarify if we can use both SNS and SQS together for decoupling microservices?

Venceslau Aragão
4 months ago

Nice detailed post. It’s really helping me in preparing for my SAP-C02 exam.

Burkhardt Fromme
3 months ago

Anyone here used AWS Step Functions with Lambda for stateful workflows? How’s the performance?

Barış Özbey
3 months ago

This blog post is a life-saver. Appreciate the clear explanations!

Jordan Foster
3 months ago

What about error handling in AWS Step Functions? Any best practices?

Joanna Berger
4 months ago

Interesting read, but the section on SQS could have been more detailed.

23
0
Would love your thoughts, please comment.x
()
x