-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquery_receiver.py
51 lines (43 loc) · 1.27 KB
/
query_receiver.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import json
import os
import boto3
import logging
import time
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core import patch_all
from botocore.exceptions import ClientError
logger = logging.getLogger()
logger.setLevel(logging.INFO)
patch_all()
#
# https://github.com/awsdocs/aws-lambda-developer-guide/blob/main/sample-apps/blank-python/function/lambda_function.py
#
def handler(event, context):
# TODO
# check duplicate query job id from DynamoDb
#
try:
body = event['body']
sqsUrl = os.environ['SQS_URL']
logging.info('sqsUrl{}, send_message:{}'.format(sqsUrl, body))
sqs_client = boto3.client('sqs')
res = sqs_client.send_message(QueueUrl=sqsUrl, MessageBody=body)
time.sleep(1)
return {
"statusCode": 200,
"body": json.dumps({
"msg ": 'OK',
"requestBody": body,
"sqsResponse ": res
})
}
except ClientError as e:
logging.error(e)
return {
"statusCode": 500,
"body": json.dumps({
"msg ": 'ERROR',
"requestBody": body,
"sqsResponse ": e
})
}