Skip to content

Instantly share code, notes, and snippets.

@ej-acebedo
Created February 1, 2023 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ej-acebedo/b0124252d650c7578ead9fff18f2bf7a to your computer and use it in GitHub Desktop.
Save ej-acebedo/b0124252d650c7578ead9fff18f2bf7a to your computer and use it in GitHub Desktop.
---
AWSTemplateFormatVersion: '2010-09-09'
Resources:
TDSQSQueue:
Type: 'AWS::SQS::Queue'
Properties:
QueueName: evfilter-sqs-demo
TDLambdaFunction:
Type: 'AWS::Lambda::Function'
Properties:
Code:
ZipFile: |
import json
def lambda_handler(event, context):
body = json.loads(event['Records'][0]['body'])
price = body["price"]
print("Price: " + "$" + str(price))
Handler: index.lambda_handler
Role: !GetAtt TDLambdaExecutionRole.Arn
Runtime: python3.8
Timeout: 30
TDLambdaExecutionRole:
Type: 'AWS::IAM::Role'
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'sts:AssumeRole'
Principal:
Service:
- lambda.amazonaws.com
Policies:
- PolicyName: main
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- 'sqs:ReceiveMessage'
- 'sqs:GetQueueAttributes'
- 'sqs:DeleteMessage'
Resource: !GetAtt TDSQSQueue.Arn
- Effect: Allow
Action:
- 'logs:CreateLogGroup'
Resource: !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:*"
- Effect: Allow
Action:
- 'logs:CreateLogStream'
- 'logs:PutLogEvents'
Resource: !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*"
TDEventSourceMapping:
Type: 'AWS::Lambda::EventSourceMapping'
Properties:
EventSourceArn: !GetAtt TDSQSQueue.Arn
FunctionName: !GetAtt TDLambdaFunction.Arn
BatchSize: 1
FilterCriteria:
Filters:
- Pattern: "{\"body\":{\"price\":[ { \"numeric\": [ \">\", 50 ] } ]}}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment