AWS SDK and Messaging/Streaming

Work with AWS SDK, develop SQS/Kinesis integrations, Dead Letter Queues, and retry patterns.

DVA-C02 is a developer exam that tests not just cloud infrastructure knowledge, but also how you actually write code to work with AWS services. This article explains, in beginner-friendly terms, how developers communicate with AWS services (SDK), how to exchange messages safely (SQS), and how to process real-time data (Kinesis).

 

AWS SDK Basics — Controlling AWS Services Through Code

The SDK (Software Development Kit) is a collection of tools that lets developers use programming languages like Python, Java, or Node.js to operate AWS services through code. Think of it as a translator that lets your code talk to AWS services. If you want to upload a file to S3 or save data to DynamoDB from your Python code, you use the SDK.

To use AWS from your code, you need credentials to prove who you are. The SDK follows a fixed order (the credential chain) when looking for these credentials. It first checks environment variables, then the shared credentials file, and finally the IAM role attached to the server. Knowing this order helps you quickly resolve "why am I getting a permission error?" situations.

Region configuration is about specifying which AWS data center (region) to use when creating an SDK client. This can also be set via environment variables.

Pagination is a feature where the SDK automatically splits large result sets across multiple pages when there are too many results to return at once. You receive the results in chunks, like chapters in a book.

 

SQS Development — Safe Message Delivery

SQS is a postal system for safely exchanging messages between services. The sender (producer) and receiver (consumer) don't need to be directly connected.

Message Lifecycle

Let's walk through how a message is processed step by step.

First, the producer sends a message to the queue. When a consumer picks up the message, the visibility timeout starts at that moment. The visibility timeout is a temporary lock that says "this message is being processed — other consumers, hands off." Once the consumer finishes processing, it deletes the message. If the message is not deleted within the visibility timeout (due to processing failure or delay), it reappears in the queue and another consumer can handle it.

Dead Letter Queue (DLQ)

Some messages may keep failing no matter how many times they are retried. Leaving these messages alone causes repeated re-processing attempts that waste resources. The DLQ moves messages that have failed more than a set number of times (maxReceiveCount) to a separate isolation queue for safekeeping. Developers can later analyze the DLQ to find the root cause of errors. Think of it like an isolation ward in a hospital.

Long Polling vs Short Polling

There are two ways to fetch messages from SQS.

Short Polling immediately asks the queue "are there any messages?" and returns an empty response right away if there are none. The problem is that it keeps asking even when there are no messages, wasting API call costs.

Long Polling waits up to 20 seconds for a message to arrive. You set this with WaitTimeSeconds. Empty responses are reduced, API call counts go down, and costs are lower. Long Polling is generally the recommended approach.

!Short Polling versus Long Polling

Kinesis Streaming — Real-Time Data Processing

Unlike SNS and SQS, Kinesis is a streaming service that processes large volumes of data in real time. While SNS and SQS deal with individual messages, Kinesis handles data that flows continuously like a river. For example, it can be used to analyze the usage logs of millions of app users in real time, or to process IoT sensor data.

Kinesis Data Streams is organized into units called shards. Think of shards as lanes on a highway. Producers use partition keys to direct data to specific lanes (shards), and consumers read data from each lane.

Enhanced Fan-out is a feature that guarantees dedicated throughput per consumer when multiple consumers are reading from the same stream. Each consumer independently receives data at 2MB per second per shard.

The data retention period defaults to 24 hours and can be extended to up to 365 days.

 

Resilient Code Patterns

Retry Logic — Exponential Backoff

When a network error or temporary service outage occurs, retrying immediately can actually put more load on the server. Exponential Backoff doubles the retry interval each time a failure occurs: retry after 1 second, then after 2 seconds if that fails, then 4 seconds, then 8 seconds, and so on. This is built into the AWS SDK by default but may need custom implementation in some cases.

Circuit Breaker Pattern

Like a circuit breaker in electrical systems, this pattern temporarily stops calling an external service when it keeps failing. If you keep sending requests to a consistently failing service, your own service can slow down or go offline as well. The Circuit Breaker decides "this service is having problems right now, so I'll cut the connection temporarily," preventing failures from spreading across the entire system.

 

Exam Key Points

"Move failed messages to a separate queue" -- Dead Letter Queue

"Reduce API calls and avoid empty responses" -- Long Polling (WaitTimeSeconds)

"Retry with progressively longer intervals" -- Exponential Backoff

"Stop calling a failing external service" -- Circuit Breaker pattern

"Real-time data streaming" -- Kinesis Data Streams

"Dedicated throughput per consumer" -- Kinesis Enhanced Fan-out

"Order in which SDK looks for credentials" -- Credential chain

SQS visibility timeout must be set longer than the processing time

Back to blog list