Automatically change the rds database instance type using the lambda function
In this video we will change the RDS database type using the python lambda function Code used in this video :- import sys import botocore import boto3 import json 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='RDS_Instance_Modification_Function' ) DBinstance = funcResponse['Environment']['Variables']['DBInstanceName'] DBinstanceClass = funcResponse['Environment']['Variables']['DBinstanceClass'] print(f'Starting RDS service for DBInstance: {DBinstance}') print(f'RDS instance class: {DBinstanceClass}') response = rds.modify_db_instance(DBInstanceIdentifier=DBinstance, DBInstanceClass=DBinstanceClass, ApplyImmediately=True) print(f'Success :: {response}') return json.dumps(dict(abc=123)) except ClientError as e: return json.dumps(dict(error=str(e))) return json.dumps(dict(abc=12345)) **************************************************************************** Additional Policy added in the IAM cosole :- { "Effect": "Allow", "Action": "lambda:GetFunctionConfiguration", "Resource": "Your lambda function ARN" }
Download
0 formatsNo download links available.