ποΈ Automated Priorities: Deploying SQS & SNS with CloudFormation
Hey Cloud Architects π
Welcome to Day 47 of the #100DaysOfCloud Challenge!
Today, we are moving away from manual console configuration and embracing Infrastructure as Code (IaC). The Nautilus DevOps team needs a reliable priority queuing system where "High Priority" messages are processed before "Low Priority" ones. We'll be using AWS CloudFormation to deploy an entire stack consisting of SNS, multiple SQS queues, and a Lambda consumer.
This task is part of my hands-on practice on the KodeKloud Engineer platform, which is essential for mastering automated resource provisioning.
π― Objective
- Author a CloudFormation template (
nautilus-priority-stack.yml) to define the infrastructure. - Provision two SQS queues:
nautilus-High-Priority-Queueandnautilus-Low-Priority-Queue. - Create an SNS Topic to act as the message dispatcher.
- Deploy a Lambda function with an IAM role (
lambda_execution_role) to consume and process messages. - Verify the priority logic by publishing attributed messages via the AWS CLI.
π‘ Why Priority Queuing?
In production, not all data is created equal. Some messages (like payment processing) must be handled immediately, while others (like weekly reports) can wait. By using SNS message attributes and SQS subscriptions, we can route urgent data to a dedicated "Fast Track" queue.
πΉ Key Concepts
- CloudFormation Stack: A single unit of management for a collection of AWS resources defined in a YAML or JSON template.
-
SNS Subscription Filter Policies: The logic that tells SNS: "Only send messages with the attribute
priority: highto this specific queue." - Lambda Trigger: The mechanism that automatically invokes our function as soon as a message lands in either queue.
π οΈ Step-by-Step: IaC Workflow
πΉ Phase A: Authoring the Template
We define our resources in the nautilus-priority-stack.yml file. This includes the SQS queues, the SNS topic, and the subscription logic that separates the "High" from the "Low" priority traffic.
-
Template Path:
/root/nautilus-priority-stack.yml -
Resource Logic: Ensure the SNS subscriptions include
FilterPolicyto look for the "priority" attribute.
πΉ Phase B: Deploying the Stack
Once the template is ready, we use the AWS CLI to launch the infrastructure.
- Command:
aws cloudformation create-stack --stack-name nautilus-priority-stack --template-body file:///root/nautilus-priority-stack.yml --capabilities CAPABILITY_NAMED_IAM
-
Note: The
CAPABILITY_NAMED_IAMis required because our template creates a specific IAM role for the Lambda function.
πΉ Phase C: Message Publishing & Testing
With the stack CREATE_COMPLETE, we publish messages to the SNS topic. We include message attributes so the SNS Filter Policy knows which queue to target.
- Publishing High Priority:
aws sns publish --topic-arn $topicarn --message 'High Priority message' --message-attributes '{"priority" : { "DataType":"String", "StringValue":"high"}}'
- Publishing Low Priority:
aws sns publish --topic-arn $topicarn --message 'Low Priority message' --message-attributes '{"priority" : { "DataType":"String", "StringValue":"low"}}'
πΉ Phase D: Verification
The final step is observing the Lambda function's behavior.
-
Log Inspection: Check CloudWatch Logs for the
nautilus-priorities-queue-function. - Verification: Confirm that the high-priority messages appear in the logs processed before the low-priority ones, validating our routing and processing order.
β Verify Success
-
Stack Status:
nautilus-priority-stackis in theCREATE_COMPLETEstate. - Routing: Messages are successfully filtered into the correct queues based on their attributes.
- Processing: The Lambda function successfully consumes from both queues using its IAM permissions.
π Key Takeaways
- π Repeatability: If we need to deploy this in another region, we just run the CloudFormation template againβno manual clicking required.
- π‘οΈ Granular Filtering: SNS Filter Policies are incredibly powerful for decoupled architectures, reducing the amount of "junk" data a Lambda has to parse.
- π¦ IAM Lifecycle: By including the IAM role in the stack, the permissions are created and destroyed alongside the infrastructure, preventing "zombie" roles.
π« Common Mistakes
-
Missing Capabilities Flag: Forgetting
--capabilities CAPABILITY_NAMED_IAMwill cause the stack creation to fail immediately. -
Incorrect ARN Reference: Hardcoding ARNs in the template instead of using
!Refor!GetAttmakes the template less portable. -
Attribute Mismatch: If the
StringValuein your publish command doesn't exactly match theFilterPolicyin the template (case sensitivity matters!), the message will be dropped or ignored.
π Final Thoughts
Infrastructure as Code is the standard for modern DevOps. By mastering CloudFormation, you've moved from "Cloud Admin" to "Cloud Engineer." You now have the power to deploy complex, secure, and filtered messaging systems with a single command.
π Practice Like a Pro
Want to master AWS CloudFormation? Get hands-on experience here:
π KodeKloud Engineer - Practice Labs
π Letβs Connect
- π¬ LinkedIn: Hritik Raj
- β Support my journey on GitHub: 100 Days of Cloud





Top comments (0)