Last active
May 6, 2024 11:59
-
-
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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