UPD: updated lambda-ec2StartStop.py with logging
This commit is contained in:
parent
88cadbd0b2
commit
c010e2889d
|
@ -3,6 +3,13 @@ import boto3
|
|||
import os
|
||||
import json
|
||||
import time
|
||||
import logging
|
||||
|
||||
logging.basicConfig(
|
||||
format='%(asctime)s %(levelname)-8s %(message)s',
|
||||
level=logging.INFO,
|
||||
datefmt='%Y-%m-%d %H:%M:%S')
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def start_instances(instances: list[str]) -> dict:
|
||||
|
@ -36,11 +43,13 @@ def instance_status(instances: list[str]) -> str:
|
|||
def lambda_handler(event, context):
|
||||
instances: list[str] = json.loads(os.environ['instances'])
|
||||
if event['action'] == 'start':
|
||||
logger.info('Starting instances: ' + str(instances))
|
||||
resp = start_instances(instances)
|
||||
print(instance_status(instances))
|
||||
logger.info(instance_status(instances))
|
||||
elif event['action'] == 'stop':
|
||||
logger.info('Stopping instances: ' + str(instances))
|
||||
resp = stop_instances(instances)
|
||||
print(instance_status(instances))
|
||||
logger.info(instance_status(instances))
|
||||
else:
|
||||
resp = "Event action not provided"
|
||||
return resp
|
||||
|
|
Loading…
Reference in New Issue