Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import boto3
- import pymysql
- import sys
- region = 'eu-west-1'
- user = 'username'
- password = 'password'
- snapshot_name = 'snapshot'
- source = boto3.client('rds', region_name=region)
- def lambda_handler(event, context):
- try:
- dbs = source.describe_db_instances(DBInstanceIdentifier='new-db-instance')
- rds_host = dbs.get('DBInstances')[0].get('Endpoint').get('Address')
- print("%s")%(rds_host)
- except Exception as ex:
- print ex
- sys.exit()
- try:
- conn = pymysql.connect(host=rds_host, port=3306, user=user, passwd=password, db='mysql', connect_timeout=5)
- except Exception as ex:
- print ex
- sys.exit()
- with conn.cursor() as cur:
- cur.execute("some_SQL_script")
- cur.close()
- conn.close()
- try:
- source.delete_db_snapshot(DBSnapshotIdentifier=snapshot_name)
- source.delete_db_instance(DBInstanceIdentifier=db_instance,SkipFinalSnapshot=False,FinalDBSnapshotIdentifier=snapshot_name)
- except Exception as ex:
- print ex
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement