-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
32 lines (27 loc) · 1.06 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Blank Lambda function ref: https://github.com/awsdocs/aws-lambda-developer-guide/blob/main/sample-apps/blank-python/function/lambda_function.py
import logging
import os
import boto3 # type: ignore
import jsonpickle # type: ignore
logger = logging.getLogger()
logger.setLevel(logging.INFO)
queue_url = os.environ["QUEUE_URL"]
sqs = boto3.client('sqs')
tasks = ["Hello from Lambda #1!", "Hello from Lambda #2!"]
logger.info('## TASKS\r' + jsonpickle.encode(tasks))
def handler(event, context):
logger.info('## ENVIRONMENT VARIABLES\r' + jsonpickle.encode(dict(**os.environ)))
logger.info('## EVENT\r' + jsonpickle.encode(event))
logger.info('## CONTEXT\r' + jsonpickle.encode(context))
# Send tasks to queue
for task in tasks:
try:
response = sqs.send_message(
QueueUrl=queue_url,
MessageBody=(task),
MessageGroupId='1337',
)
logger.info('## SQS RESPONSE\r' + jsonpickle.encode(response))
except Exception as e:
logger.error(e)
raise e