├── .gitignore ├── README.md ├── role-definition.json └── sqs-enqueue.py /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AWS Lambda SQS Package 2 | 3 | This is an example AWS Lambda package for taking an incoming payload from a POST to an endpoint and enqueuing the payload using SQS (Simple Queue Service). 4 | 5 | Components: 6 | 7 | * AWS API Gateway 8 | * AWS Lambda 9 | * AWS SQS (Simple Queue Service) 10 | * AWS IAM (Identity & Access Management) 11 | 12 | --- 13 | 14 | Read all about it in this blog post: https://startupnextdoor.com/adding-to-sqs-queue-using-aws-lambda-and-a-serverless-api-endpoint 15 | -------------------------------------------------------------------------------- /role-definition.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Statement": [ 4 | { 5 | "Effect": "Allow", 6 | "Action": [ 7 | "logs:CreateLogGroup", 8 | "logs:CreateLogStream", 9 | "logs:PutLogEvents" 10 | ], 11 | "Resource": "arn:aws:logs:*:*:*" 12 | }, 13 | { 14 | "Action": [ 15 | "sqs:SendMessage", 16 | "sqs:GetQueueUrl" 17 | ], 18 | "Effect": "Allow", 19 | "Resource": "arn:aws:sqs:us-east-1:SOME_ID_HERE:test-messages" 20 | } 21 | ] 22 | } -------------------------------------------------------------------------------- /sqs-enqueue.py: -------------------------------------------------------------------------------- 1 | import boto3 2 | import json 3 | 4 | 5 | def lambda_handler(event, context): 6 | 7 | sqs = boto3.resource('sqs') 8 | 9 | queue = sqs.get_queue_by_name(QueueName='test-messages') 10 | 11 | queue.send_message(MessageBody=json.dumps(event)) 12 | --------------------------------------------------------------------------------