def get_values(event): region = None if 'region' in event: region = event['region'] modules_process = [] if 'custom' not in event: beanstalk = Beanstalk() modules_process.append(beanstalk.run(region)) ec2 = EC2() modules_process.append(ec2.run(region)) rds = RDS() modules_process.append(rds.run(region)) ssm = SSM() modules_process.append(ssm.run(region)) ses = SES() modules_process.append(ses.run(region)) elasticache = Elasticache() modules_process.append(elasticache.run(region)) else: data = str(event['custom']) if 'BEANSTALK' in data: beanstalk = Beanstalk() modules_process.append(beanstalk.run(region)) if 'INSTANCES' in data: ec2 = EC2() modules_process.append(ec2.run(region)) if 'SSM' in data: ssm = SSM() modules_process.append(ssm.run(region)) if 'ELASTICACHE' in data: elasticache = Elasticache() modules_process.append(elasticache.run(region)) if 'RDS' in data: rds = RDS() modules_process.append(rds.run(region)) if 'SES' in data: ses = SES() modules_process.append(ses.run(region)) start_all(modules_process) wait_all(modules_process) ret_dict = read_all(modules_process) return ret_dict
def deploy_resources(): rds_client = RDSClient().get_client() rds = RDS(rds_client) rds.create_postgresql_instance() print("Creating RDS PostgreSQL Instance...")
def deploy_resources(): rds_client = RDSClient().get_client() print(f'RDs client {rds_client}') rds = RDS(rds_client) rds.create_postgresql_instance() print("creating RDS PostGreSQL Instance")
def create_from_latest_snapshot(config): rds = RDS(aws_id=config['aws_access_key_id'], aws_secret_key=config['aws_secret_access_key'], aws_region=config['aws_region']) snapshot = rds.get_latest_snapshot( rds_instance_id=config['rds_instance_id']) instance = rds.create_instace_from_snapshot(snapshot, config['rds_subnet_group']) return instance.id
def ephemeral_zombie_clean(self, args): k8s = K8S() rds = RDS(self.args) route53 = ROUTE53(self.args) namespaces = k8s.get_k8s_namespaces(pattern=self.args.target_instance) rds_instances = rds.get_rds_instances( pattern=self.args.target_instance) #Check if any RDS instance does not have matching K8s NS rds_zombies = [] for rds_instance in rds_instances: found = False for ns in namespaces: if (re.search(ns, rds_instance['instance_name'])): found = True if (not found): rds_zombies.append(rds_instance) if not rds_zombies: logging.info("No ephemeral zombies found") sys.exit(0) logging.info(f"Found ephemeral zombies:{rds_zombies}") attributes = {} attributes['dns_suffix'] = self.args.dns_suffix attributes['zone_id'] = self.args.zone_id #Deleting Zombies and associated CNAME records zombie_names = [] for zombie in rds_zombies: ephemeral_name = zombie['instance_name'][:10] attributes['cname_name'] = f"{ephemeral_name}-rds" #Get All records for DNS Zone route53_records = route53.get_records_set(attributes['zone_id']) route53_record_name = f'{attributes["cname_name"]}.{attributes["dns_suffix"]}.' #Check if record exists zombie_cname_record = list( filter(lambda d: d['Name'] in [route53_record_name], route53_records)) if zombie_cname_record: logging.info( f'DNS record for {route53_record_name} found, deleting ...' ) route53.update_dns(attributes['cname_name'], attributes['dns_suffix'], attributes['zone_id'], zombie['instance_address'], action='DELETE') else: logging.info( f'DNS record for {route53_record_name} not found, skipping ...' ) zombie_names.append(zombie['instance_name']) rds.destroy_old_instances(zombie_names)
def backup_data(config): """ 1. Create an instance from the latest snapshot. 2. Backup the data to s3 given an instance. 3. Delete the instance. """ instance_id = db_instance_creater.create_from_latest_snapshot(config) print('Created instance', instance_id) data_backup_creater.dump_gzip_backkup(instance_id, config) print('Deleting instance', instance_id) rds = RDS(aws_id=config['aws_access_key_id'], aws_secret_key=config['aws_secret_access_key'], aws_region=config['aws_region']) rds.delete_instance(instance_id)
def dump_gzip_backkup(instance_id, config): rds = RDS(aws_id=config['aws_access_key_id'], aws_secret_key=config['aws_secret_access_key'], aws_region=config['aws_region']) instance = rds.get_instance(instance_id) host = rds.get_host(instance) compress_command = config.get('compress_command', 'gzip') assert compress_command in command_to_extension for db in config['databases']: s3_location = 's3://{}/{}/{}-{}.sql.{}'.format( config['s3_bucket'], config['s3_prefix'], db['name'], datetime.now().strftime('%y-%b-%d-%H-%M-%S'), command_to_extension[compress_command]) print('Backing Up', db['name'], 'to', s3_location) create_backup(host, s3_location, db_user=db['user'], db_password=db['password'], db_name=db['name'], compress_command=compress_command)
def get_rds(): rds_client = RDSClient().get_client() rds = RDS(rds_client) return rds