Search for the Right Document
< All Topics
Print

Example AWS CloudFormation Templates for Queue-Driven Systems

In the context of optimizing software and architecture for asynchronous and scheduled jobs, implementing queue-driven systems represents a key pattern to align with sustainability goals within the AWS Well-Architected Framework. Below are example AWS CloudFormation templates that deploy a basic architecture leveraging AWS services such as Amazon SQS (Simple Queue Service) and AWS Lambda for a serverless approach, which is crucial for efficient resource utilization.

**AWS CloudFormation Template Example for a Queue-Driven System**:

“`yaml
AWSTemplateFormatVersion: ‘2010-09-09’
Description: Sample CloudFormation template to create a queue-driven system for asynchronous job management.

Resources:
MyQueue:
Type: ‘AWS::SQS::Queue’
Properties:
QueueName: ‘MyQueue’

MyFunction:
Type: ‘AWS::Lambda::Function’
Properties:
Handler: index.handler
Role: !GetAtt MyLambdaExecutionRole.Arn
Code:
ZipFile: |
def handler(event, context):
# Logic to process the message from the queue
return ‘Processed’
Runtime: ‘python3.8’
Timeout: 30

MyQueueEventSourceMapping:
Type: ‘AWS::Lambda::EventSourceMapping’
Properties:
BatchSize: 10
EventSourceArn: !GetAtt MyQueue.Arn
FunctionName: !GetAtt MyFunction.Arn
Enabled: true

MyLambdaExecutionRole:
Type: ‘AWS::IAM::Role’
Properties:
RoleName: ‘MyLambdaExecutionRole’
AssumeRolePolicyDocument:
Version: ‘2012-10-17’
Statement:
– Effect: ‘Allow’
Principal:
Service: ‘lambda.amazonaws.com’
Action: ‘sts:AssumeRole’
Policies:
– PolicyName: ‘SQSSendMessagePolicy’
PolicyDocument:
Version: ‘2012-10-17’
Statement:
– Effect: ‘Allow’
Action:
– ‘sqs:SendMessage’
Resource: !GetAtt MyQueue.Arn
“`

**Key Benefits of this Architecture:**
1. **Resource Efficiency**: By utilizing AWS Lambda, resources are only consumed during execution, reducing the idle compute resources when handling jobs.
2. **Scalability**: SQS and Lambda can automatically scale based on the number of messages in the queue, ensuring that no resources are wasted during low-traffic periods.
3. **Asynchronous Processing**: This approach allows for the decoupling of request and processing, which can lead to increased system resilience.
4. **Lower Carbon Footprint**: The serverless nature of this design contributes to sustainability goals by ensuring that computing resources are utilized efficiently, thereby minimizing energy consumption.

By employing efficient design patterns like the queue-driven system illustrated in this example, organizations can optimize their resource utilization and contribute significantly to their sustainability targets.

Table of Contents