Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. import boto3
  2. import pymysql
  3. import sys
  4.  
  5. region = 'eu-west-1'
  6. user = 'username'
  7. password = 'password'
  8. snapshot_name = 'snapshot'
  9.  
  10. source = boto3.client('rds', region_name=region)
  11.  
  12. def lambda_handler(event, context):
  13. try:
  14. dbs = source.describe_db_instances(DBInstanceIdentifier='new-db-instance')
  15. rds_host = dbs.get('DBInstances')[0].get('Endpoint').get('Address')
  16. print("%s")%(rds_host)
  17. except Exception as ex:
  18. print ex
  19. sys.exit()
  20.  
  21. try:
  22. conn = pymysql.connect(host=rds_host, port=3306, user=user, passwd=password, db='mysql', connect_timeout=5)
  23. except Exception as ex:
  24. print ex
  25. sys.exit()
  26. with conn.cursor() as cur:
  27. cur.execute("some_SQL_script")
  28. cur.close()
  29. conn.close()
  30.  
  31. try:
  32. source.delete_db_snapshot(DBSnapshotIdentifier=snapshot_name)
  33. source.delete_db_instance(DBInstanceIdentifier=db_instance,SkipFinalSnapshot=False,FinalDBSnapshotIdentifier=snapshot_name)
  34. except Exception as ex:
  35. print ex
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement