-
Notifications
You must be signed in to change notification settings - Fork 0
/
lambda_function.py
37 lines (24 loc) · 1.05 KB
/
lambda_function.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
# import required modules
import requests, json
import botocore
import botocore.session
from aws_secretsmanager_caching import SecretCache, SecretCacheConfig
import re
def startRachio(rachioAPIKey):
print("Starting Rachio")
rachioURL = "https://api.rach.io/1/public/schedulerule/start"
rachioPayload = {"id": "e9e49b85-0de7-41ff-9009-ae1cdae9fc30"}
rachioHeaders = {
"Content-Type": "application/json",
"Authorization": "Bearer " + rachioAPIKey
}
response = requests.request("PUT", rachioURL, json=rachioPayload, headers=rachioHeaders)
def lambda_handler(event, context):
# if __name__ == "__main__":
client = botocore.session.get_session().create_client('secretsmanager')
cache_config = SecretCacheConfig()
cache = SecretCache( config = cache_config, client = client)
rachioAPIKey = cache.get_secret_string('arn:aws:secretsmanager:us-east-1:514894476795:secret:rachioAPIKey-pztCKo')
rachioAPIKey = re.sub("{\"apikey\":\"", "", rachioAPIKey)
rachioAPIKey = re.sub("\"}", "", rachioAPIKey)
startRachio(rachioAPIKey)