import sys
import botocore
import boto3
from botocore.exceptions import ClientError
def lambda_handler(event, context):
rds = boto3.client('rds')
lambdaFunc = boto3.client('lambda')
print ('Trying to get Environment variable')
try:
funcResponse = lambdaFunc.get_function_configuration(
FunctionName='RDSInstanceReboot'
)
DBinstance = funcResponse['Environment']['Variables']['DBInstanceName']
print ('Stoping RDS service for DBInstance : ' + DBinstance)
except ClientError as e:
print(e)
try:
response = rds.reboot_db_instance(
DBInstanceIdentifier=DBinstance
)
print ('Success :: ')
return response
except ClientError as e:
print(e)
return
{
'message' : "Script execution completed. See Cloudwatch logs for complete output"
}
However when I run I get the following output:
[ERROR] Runtime.MarshalError: Unable to marshal response: datetime.datetime(2021, 12, 5, 1, 45, 5, 506000, tzinfo=tzlocal()) is not JSON serializable
Traceback (most recent call last):
Please use the following, to return json string using dumps :
import json
...
...
return json.dumps(response, default=str)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.