Skip to content

Instantly share code, notes, and snippets.

@quiver
Last active May 6, 2024 11:59
Show Gist options
  • Save quiver/4dda98e0f54885f59fe1808f5373e110 to your computer and use it in GitHub Desktop.
Save quiver/4dda98e0f54885f59fe1808f5373e110 to your computer and use it in GitHub Desktop.
AWS CloudFormation Template for SQS - Lambda Event source Integration https://dev.classmethod.jp/articles/consistent-consumer-pipelining-with-eventbridge-pipes/
Resources:
QueueForLambda:
Type: 'AWS::SQS::Queue'
LambdaServiceRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: 'sts:AssumeRole'
Effect: Allow
Principal:
Service: lambda.amazonaws.com
Version: '2012-10-17'
ManagedPolicyArns:
- 'Fn::Join':
- ''
- - 'arn:'
- Ref: 'AWS::Partition'
- ':iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
LambdaServiceRoleDefaultPolicy:
Type: 'AWS::IAM::Policy'
Properties:
PolicyDocument:
Statement:
- Action:
- 'sqs:ChangeMessageVisibility'
- 'sqs:DeleteMessage'
- 'sqs:GetQueueAttributes'
- 'sqs:GetQueueUrl'
- 'sqs:ReceiveMessage'
Effect: Allow
Resource:
'Fn::GetAtt':
- QueueForLambda
- Arn
Version: '2012-10-17'
PolicyName: LambdaServiceRoleDefaultPolicy
Roles:
- Ref: LambdaServiceRole
LambdaForSQS:
Type: 'AWS::Lambda::Function'
Properties:
Code:
ZipFile: |-
def handler(event, context):
for record in event['Records']:
print(record['body'])
Handler: index.handler
Role:
'Fn::GetAtt':
- LambdaServiceRole
- Arn
Runtime: python3.11
DependsOn:
- LambdaServiceRoleDefaultPolicy
- LambdaServiceRole
LambdaSqsEventSourceSqs:
Type: 'AWS::Lambda::EventSourceMapping'
Properties:
EventSourceArn:
'Fn::GetAtt':
- QueueForLambda
- Arn
FunctionName:
Ref: LambdaForSQS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment