diff --git a/sns-sqs-lambda/SNS_SQS_Lambda.yaml b/sns-sqs-lambda/SNS_SQS_Lambda.yaml new file mode 100644 index 000000000..f745e4716 --- /dev/null +++ b/sns-sqs-lambda/SNS_SQS_Lambda.yaml @@ -0,0 +1,52 @@ +AWSTemplateFormatVersion: 2010-09-09 +Resources: + SNSTopic: + Type: 'AWS::SNS::Topic' + Properties: + TopicName: SNSServerLessPatternTopic + Subscription: + - Endpoint: + Fn::GetAtt: + - "MyQueueServerLessPattern" + - "Arn" + Protocol: "sqs" + Metadata: + 'AWS::CloudFormation::Designer': + id: 4a1dceb8-54fd-4790-9df0-d6f4dbed73ad + MyQueueServerLessPattern: + Type: 'AWS::SQS::Queue' + Properties: + QueueName : ServerLessPatternQueue + VisibilityTimeout: 720 + LambdaFunction: + Type: 'AWS::Lambda::Function' + Properties: + Handler: LambdaFunctoin.handler + Role: !GetAtt LambdaExecutionRole.Arn + Runtime: python3.7 + Timeout: 120 + MemorySize: 512 + Code : + ZipFile : | + import json + def lambda_handler(event, context): + print(event) + LambdaExecutionRole: + Type: 'AWS::IAM::Role' + Properties: + AssumeRolePolicyDocument: + Version: "2012-10-17" + Statement: + - Effect: Allow + Principal: + Service: + - lambda.amazonaws.com + Action: + - 'sts:AssumeRole' + ManagedPolicyArns : + - 'arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole' + EventSourceMapping: + Type: AWS::Lambda::EventSourceMapping + Properties: + FunctionName: !GetAtt LambdaFunction.Arn + EventSourceArn: !GetAtt MyQueueServerLessPattern.Arn diff --git a/sns-sqs-lambda/read.md b/sns-sqs-lambda/read.md new file mode 100644 index 000000000..3f7ab4b04 --- /dev/null +++ b/sns-sqs-lambda/read.md @@ -0,0 +1,25 @@ +SNS SQS LAMBDA + +This project contains source code and supporting files for a serverless application that you can deploy with the AWS Cloudformation. It includes the following files and folders. + +The project creates a SNS Topic and Subscribes a SQS Queue to it. The Subscribed SQS Queue is polled by Lambda Event Source Mapping and invokes the Lambda function with the messages present in the queue. + +Requirements + +Create an AWS account if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources. + +AWS CLI installed and configured + +Git Installed + +Deployment Instructions +Create a new directory, navigate to that directory in a terminal and clone the GitHub repository: + +git clone https://github.com/aws-samples/serverless-patterns +Change directory to the pattern directory: + +cd sns-sqs-lambda + +From the command line, use AWS CLI to deploy the AWS resources for the pattern as specified in the main.tf file: + +aws cloudformation create-stack --stack-name myteststack --template-body file://SNS_SQS_Lambda.yaml