Automatically change the rds database instance type using the lambda function

Опубликовано: 14 Декабрь 2023
на канале: Devops TerraByte
245
3

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"
}


Смотрите видео Automatically change the rds database instance type using the lambda function онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Devops TerraByte 14 Декабрь 2023, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 245 раз и оно понравилось 3 людям.