Advertisement
mobilefish

Untitled

Jan 7th, 2021
775
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 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.    try:
  11.        funcResponse = lambdaFunc.get_function_configuration(
  12.            FunctionName='StopRDSInstances'
  13.        )
  14.        DBinstance = funcResponse['Environment']['Variables']['DBInstanceName']
  15.        print('Stopping RDS service for DBInstance : ' + DBinstance)
  16.    except ClientError as e:
  17.        print(e)
  18.    try:
  19.        response = rds.stop_db_instance(
  20.            DBInstanceIdentifier=DBinstance
  21.        )
  22.        print('Success :: ')
  23.        return response
  24.    except ClientError as e:
  25.        print(e)
  26.    return
  27.    {
  28.        'message' : "Script execution completed. See Cloudwatch logs for complete output"
  29.    }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement