Skip to content

Instantly share code, notes, and snippets.

@quiver
Last active May 20, 2024 07:12
Show Gist options
  • Save quiver/f1cbb07c2c469379fa73c6d4f55fdb67 to your computer and use it in GitHub Desktop.
Save quiver/f1cbb07c2c469379fa73c6d4f55fdb67 to your computer and use it in GitHub Desktop.
AWS CloudFormation Template for SQS - EventBridge Pipes - Lambda Integration https://dev.classmethod.jp/articles/consistent-consumer-pipelining-with-eventbridge-pipes/
---
Resources:
QueueForPipe:
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"
LambdaForPipe:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: |-
def handler(event, context):
for record in event:
print(record['body'])
Handler: index.handler
Role:
Fn::GetAtt:
- LambdaServiceRole
- Arn
Runtime: python3.11
DependsOn:
- LambdaServiceRole
PipeRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: pipes.amazonaws.com
Version: '2012-10-17'
PipeRoleDefaultPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyDocument:
Statement:
- Action:
- sqs:ChangeMessageVisibility
- sqs:DeleteMessage
- sqs:GetQueueAttributes
- sqs:GetQueueUrl
- sqs:ReceiveMessage
Effect: Allow
Resource:
Fn::GetAtt:
- QueueForPipe
- Arn
- Action: lambda:InvokeFunction
Effect: Allow
Resource:
- Fn::GetAtt:
- LambdaForPipe
- Arn
- Fn::Join:
- ''
- - Fn::GetAtt:
- LambdaForPipe
- Arn
- ":*"
Version: '2012-10-17'
PolicyName: PipeRoleDefaultPolicy
Roles:
- Ref: PipeRole
Pipe:
Type: AWS::Pipes::Pipe
Properties:
RoleArn:
Fn::GetAtt:
- PipeRole
- Arn
Source:
Fn::GetAtt:
- QueueForPipe
- Arn
Target:
Fn::GetAtt:
- LambdaForPipe
- Arn
TargetParameters:
LambdaFunctionParameters:
InvocationType: REQUEST_RESPONSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment