Created
October 15, 2020 01:34
-
-
Save lorne-luo/fef76efba81569fed953f1b066802524 to your computer and use it in GitHub Desktop.
SQS Queue as Lambda Trigger in AWS CloudFormation
This file contains 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
AWSTemplateFormatVersion : 2010-09-09 | |
Resources: | |
LambdaExecutionRole: | |
Type: AWS::IAM::Role | |
Properties: | |
AssumeRolePolicyDocument: | |
Version: '2012-10-17' | |
Statement: | |
- Effect: Allow | |
Principal: | |
Service: | |
- lambda.amazonaws.com | |
Action: | |
- sts:AssumeRole | |
Policies: | |
- PolicyName: allowLambdaLogs | |
PolicyDocument: | |
Version: '2012-10-17' | |
Statement: | |
- Effect: Allow | |
Action: | |
- logs:* | |
Resource: arn:aws:logs:*:*:* | |
- PolicyName: allowSqs | |
PolicyDocument: | |
Version: '2012-10-17' | |
Statement: | |
- Effect: Allow | |
Action: | |
- sqs:ReceiveMessage | |
- sqs:DeleteMessage | |
- sqs:GetQueueAttributes | |
- sqs:ChangeMessageVisibility | |
Resource: !GetAtt MyQueue.Arn | |
LambdaFunction: | |
Type: AWS::Lambda::Function | |
Properties: | |
Code: | |
S3Bucket: my-source-bucket | |
S3Key: lambda/my-nodejs-app.zip | |
Handler: index.handler | |
Role: !GetAtt LambdaExecutionRole.Arn | |
Runtime: nodejs8.10 | |
Timeout: 60 | |
MemorySize: 512 | |
LambdaFunctionEventSourceMapping: | |
Type: AWS::Lambda::EventSourceMapping | |
Properties: | |
BatchSize: 10 | |
Enabled: true | |
EventSourceArn: !GetAtt MyQueue.Arn | |
FunctionName: !GetAtt LambdaFunction.Arn | |
MyQueue: | |
Type: AWS::SQS::Queue | |
Properties: | |
DelaySeconds: 0 | |
VisibilityTimeout: 120 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment