Advertisement
mobilefish

Untitled

Jan 10th, 2021
1,172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import sys
  2. import botocore
  3. import boto3
  4. from botocore.exceptions import ClientError
  5. def lambda_handler(event, context):
  6.    rds = boto3.client('rds')
  7.    lambdaFunc = boto3.client('lambda')
  8.    print('Trying to get Environment variable')
  9.    
  10.    DBinstance =''
  11.  
  12.  
  13.    try:
  14.        funcResponse = lambdaFunc.get_function_configuration(
  15.            FunctionName='StopRDSInstances'
  16.        )
  17.        DBinstance = funcResponse['Environment']['Variables']['DBInstanceName']
  18.        print('Stopping RDS service for DBInstance : ' + DBinstance)
  19.    except ClientError as e:
  20.        print(e)
  21.        
  22.    DBInstanceIdentifier=''
  23.    try:
  24.        response = rds.stop_db_instance(
  25.            DBInstanceIdentifier=DBinstance
  26.        )
  27.        print('Success :: ')
  28.        return response
  29.    except ClientError as e:
  30.        print(e)
  31.    return
  32.    {
  33.        'message' : "Script execution completed. See Cloudwatch logs for complete output"
  34.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement