How to use describe_cluster_snapshots method in localstack

Best Python code snippet using localstack_python

redshift_hook.py

Source:redshift_hook.py Github

copy

Full Screen

...56 SkipFinalClusterSnapshot=skip_final_cluster_snapshot,57 FinalClusterSnapshotIdentifier=final_cluster_snapshot_identifier58 )59 return response['Cluster'] if response['Cluster'] else None60 def describe_cluster_snapshots(self, cluster_identifier):61 """62 Gets a list of snapshots for a cluster63 :param cluster_identifier: unique identifier of a cluster64 :type cluster_identifier: str65 """66 response = self.get_conn().describe_cluster_snapshots(67 ClusterIdentifier=cluster_identifier68 )69 if 'Snapshots' not in response:70 return None71 snapshots = response['Snapshots']72 snapshots = filter(lambda x: x['Status'], snapshots)73 snapshots.sort(key=lambda x: x['SnapshotCreateTime'], reverse=True)74 return snapshots75 def restore_from_cluster_snapshot(self, cluster_identifier, snapshot_identifier):76 """77 Restores a cluster from its snapshot78 :param cluster_identifier: unique identifier of a cluster79 :type cluster_identifier: str80 :param snapshot_identifier: unique identifier for a snapshot of a cluster...

Full Screen

Full Screen

lambda_function.py

Source:lambda_function.py Github

copy

Full Screen

...9redshift_client = boto3.client('redshift')10def lambda_handler(event, context):11 for cluster in [instance for instance in redshift_client.describe_clusters()['Clusters']]:12 print('Creating snapshots for cluster {}'.format(cluster['ClusterIdentifier']))13 automated_snapshots = [s for s in redshift_client.describe_cluster_snapshots(ClusterIdentifier=cluster['ClusterIdentifier'])['Snapshots'] if (s['SnapshotType'] == 'automated' and s['Status'] == 'available')]14 sorted_automated_snapshots = sorted(automated_snapshots, key=itemgetter('SnapshotCreateTime'), reverse=True)15 if (len(sorted_automated_snapshots) > 0):16 latest_automated_snapshot = sorted_automated_snapshots[0]17 identifier = re.search('.+?:(.*)', latest_automated_snapshot['SnapshotIdentifier']).group(1)18 print('creating {} from {}'.format(identifier, latest_automated_snapshot['SnapshotIdentifier']))19 try:20 create_response = redshift_client.copy_cluster_snapshot(21 SourceSnapshotIdentifier=latest_automated_snapshot['SnapshotIdentifier'],22 TargetSnapshotIdentifier='manual-{}'.format(identifier),23 )['Snapshot']24 redshift_client.create_tags(25 ResourceName='arn:aws:redshift:{}:{}:snapshot:{}/{}'.format(26 create_response['AvailabilityZone'][:-1],27 create_response['OwnerAccount'],28 create_response['ClusterIdentifier'],29 'manual-{}'.format(identifier)30 ),31 Tags=[{32 'Key': 'Managed_by',33 'Value': 'lambda:redshift_snapshot_copier'34 }]35 )36 except redshift_client.exceptions.ClusterSnapshotQuotaExceededFault:37 pass38 except redshift_client.exceptions.ClientError as e:39 if ('Cannot create more than' in str(e)):40 pass41 elif ('has already been copied' in str(e)):42 print('Skipping already created snapshot')43 pass44 else:45 raise(e)46 else:47 print('No automated snaphots found for cluster {}'.format(cluster['ClusterIdentifier']))48 print('Clearing old snapshots for cluster {}'.format(cluster['ClusterIdentifier']))49 manual_snapshots = [s for s in redshift_client.describe_cluster_snapshots(ClusterIdentifier=cluster['ClusterIdentifier'])['Snapshots'] if (s['SnapshotType'] != 'automated' and s['Status'] == 'available')]50 for snapshot in manual_snapshots:51 match = re.search('^(manual-).*', snapshot['SnapshotIdentifier'])52 if (match is not None and match.group(1) is not None):53 response = redshift_client.describe_tags(54 ResourceName='arn:aws:redshift:{}:{}:snapshot:{}/{}'.format(55 snapshot['AvailabilityZone'][:-1],56 snapshot['OwnerAccount'],57 snapshot['ClusterIdentifier'],58 snapshot['SnapshotIdentifier']59 ),60 TagKeys=[61 'Managed_by',62 ],63 TagValues=[...

Full Screen

Full Screen

redshift.py

Source:redshift.py Github

copy

Full Screen

...29 print('Deleting Redshift snapshot {}'.format(snapshot_id))30 client.delete_cluster_snapshot(31 SnapshotIdentifier=snapshot_id32 )33 while client.describe_cluster_snapshots()['Snapshots']:34 time.sleep(5)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful