-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
54 lines (45 loc) · 1.57 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from redis import Redis
import boto3
import json
import uuid
import datetime
import os
import botocore
from botocore.exceptions import ClientError
from aws_lambda_powertools.utilities import parameters
session = boto3.session.Session()
if os.environ.get('REDIS_SECRET_NAME'):
redis_password = parameters.get_secret(
os.environ.get('REDIS_SECRET_NAME'), max_age=os.environ.get('SECRET_CACHE_AGE', default=300))
else:
redis_password = os.environ.get('REDIS_PASSWORD')
def lambda_handler(event, context):
r = Redis(
host=os.environ.get('REDIS_HOST'),
port=os.environ.get('REDIS_PORT'),
db=os.environ.get('REDIS_DB'),
username=os.environ.get('REDIS_USERNAME'),
password=redis_password)
id = str(uuid.uuid4())
message_body = {
'class': os.environ.get('SCHEDULED_JOB_CLASS'),
'args': [
{
'job_class': event,
'job_id': id,
'queue_name': os.environ.get('SCHEDULED_QUEUE', default='scheduled'),
'priority': None,
'enqueued_at': datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
'locale': 'en',
'timezone': 'UTC',
'executions': 0,
'exception_executions': {},
'arguments': []
}
]
}
r.rpush(
f"{os.environ.get('SCHEDULED_QUEUE_PREFIX')}:{os.environ.get('SCHEDULED_QUEUE')}", json.dumps(message_body))
# if __name__ == "__main__":
# event = "Scheduled::QueueMessageLockJob"
# lambda_handler(event, None)