def nuke(self, older_than_seconds: float) -> None: """S3 bucket deleting function. Deleting all s3 buckets with a timestamp greater than older_than_seconds. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for s3_bucket in self.list_buckets(older_than_seconds): try: # Delete all objects in bucket bucket = self.s3_resource.Bucket(s3_bucket) bucket.object_versions.delete() bucket.objects.delete() except ClientError as exc: nuke_exceptions("s3 object", s3_bucket, exc) try: # Delete bucket self.s3.delete_bucket(Bucket=s3_bucket) print("Nuke s3 bucket {0}".format(s3_bucket)) except ClientError as exc: nuke_exceptions("s3 bucket", s3_bucket, exc)
def nuke(self, older_than_seconds: float) -> None: """Spot request and spot fleet deleting function. Deleting all Spot request and spot fleet deleting function with a timestamp greater than older_than_seconds. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for spot_request in self.list_requests(older_than_seconds): try: self.ec2.cancel_spot_instance_requests( SpotInstanceRequestIds=[spot_request]) print("Cancel spot instance request {0}".format(spot_request)) except ClientError as exc: nuke_exceptions("spot request", spot_request, exc) for spot_fleet in self.list_fleet(older_than_seconds): try: self.ec2.cancel_spot_fleet_requests( SpotFleetRequestIds=[spot_fleet]) print("Nuke spot fleet request {0}".format(spot_fleet)) except ClientError as exc: nuke_exceptions("spot fleet", spot_fleet, exc)
def nuke(self, older_than_seconds: float) -> None: """Elastic Beanstalk deleting function. Deleting all Elastic Beanstalk with a timestamp greater than older_than_seconds. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for app in self.list_apps(older_than_seconds): try: self.elasticbeanstalk.delete_application( ApplicationName=app, TerminateEnvByForce=True) print("Nuke elasticbeanstalk application{0}".format(app)) except ClientError as exc: nuke_exceptions("elasticbenstalk app", app, exc) for env in self.list_envs(older_than_seconds): try: self.elasticbeanstalk.terminate_environment( EnvironmentId=env, ForceTerminate=True) print("Nuke elasticbeanstalk environment {0}".format(env)) except ClientError as exc: nuke_exceptions("elasticbenstalk env", env, exc)
def nuke_instances(self, time_delete: float) -> None: """Ec2 instance delete function. Delete ec2 instances with a timestamp greater than time_delete :param int time_delete: The timestamp in seconds used from which the aws resource will be deleted """ instance_terminating = [] ec2_waiter = self.ec2.get_waiter("instance_terminated") for instance in self.list_instances(time_delete): try: self.ec2.terminate_instances(InstanceIds=[instance]) print("Terminate instances {0}".format(instance)) except ClientError as exc: nuke_exceptions("instance", instance, exc) else: instance_terminating.append(instance) if instance_terminating: try: ec2_waiter.wait( InstanceIds=instance_terminating, WaiterConfig={ "Delay": 10, "MaxAttempts": 30 }, ) except WaiterError as exc: nuke_exceptions("instance waiter", instance_terminating, exc)
def nuke(self, older_than_seconds: float) -> None: """Rds resources deleting function. Deleting all rds resources with a timestamp greater than older_than_seconds. That include: - Aurora clusters - rds instances - snapshots - subnets - param groups :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for instance in self.list_instances(older_than_seconds): try: self.rds.delete_db_instance(DBInstanceIdentifier=instance, SkipFinalSnapshot=True) print("Stop rds instance {0}".format(instance)) except ClientError as exc: nuke_exceptions("rds instance", instance, exc) for cluster in self.list_clusters(older_than_seconds): try: self.rds.delete_db_cluster(DBClusterIdentifier=cluster, SkipFinalSnapshot=True) print("Nuke rds cluster {0}".format(cluster)) except ClientError as exc: nuke_exceptions("rds cluster", cluster, exc)
def nuke(self, older_than_seconds: float) -> None: """Autoscaling deleting function. Deleting all Autoscaling Groups and Launch Configurations resources with a timestamp greater than older_than_seconds. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for scaling in self.list_asg(older_than_seconds): try: self.asg.delete_auto_scaling_group( AutoScalingGroupName=scaling, ForceDelete=True) print("Nuke Autoscaling Group {0}".format(scaling)) except ClientError as exc: nuke_exceptions("autoscaling group", scaling, exc) for launch_conf in self.list_launch_confs(older_than_seconds): try: self.asg.delete_launch_configuration( LaunchConfigurationName=launch_conf) print("Nuke Launch Configuration {0}".format(launch_conf)) except ClientError as exc: nuke_exceptions("launch configuration", launch_conf, exc)
def nuke(self) -> None: """Network acl delete function.""" for net_acl in self.list_network_acls(): try: self.ec2.delete_network_acl(NetworkAclId=net_acl) print("Nuke ec2 network acl {0}".format(net_acl)) except ClientError as exc: nuke_exceptions("network acl", net_acl, exc)
def nuke_placement_groups(self) -> None: """Ec2 placement group delete function.""" for placement_group in self.list_placement_groups(): try: self.ec2.delete_placement_group(GroupName=placement_group) print("Nuke Placement Group {0}".format(placement_group)) except ClientError as exc: nuke_exceptions("placement group", placement_group, exc)
def nuke(self) -> None: """Keypair deleting function. Deleting all Keypair """ for keypair in self.list_keypair(): try: self.ec2.delete_key_pair(KeyName=keypair) print("Nuke Key Pair {0}".format(keypair)) except ClientError as exc: nuke_exceptions("keypair", keypair, exc)
def nuke_target_groups(self) -> None: """Elbv2 Target group delete function. Deleting all elbv2 target groups """ for target_group in self.list_target_groups(): try: self.elbv2.delete_target_group(TargetGroupArn=target_group) print("Nuke Target Group {0}".format(target_group)) except ClientError as exc: nuke_exceptions("lb target group", target_group, exc)
def nuke(self) -> None: """Eip deleting function. Delete all eip """ for eip in self.list_eips(): try: self.ec2.release_address(AllocationId=eip) print("Nuke elastic ip {0}".format(eip)) except ClientError as exc: nuke_exceptions("eip", eip, exc)
def nuke_param_groups(self) -> None: """Elasticache param group deleting function. Deleting elasticache parameter groups """ for param in self.list_param_groups(): try: self.elasticache.delete_cache_parameter_group( CacheParameterGroupName=param) print("Nuke elasticache param {0}".format(param)) except ClientError as exc: nuke_exceptions("elasticache param", param, exc)
def nuke_subnets(self) -> None: """Elasticache subnet deleting function. Deleting elasticache subnets """ for subnet in self.list_subnets(): try: self.elasticache.delete_cache_subnet_group( CacheSubnetGroupName=subnet) print("Nuke elasticache subnet{0}".format(subnet)) except ClientError as exc: nuke_exceptions("elasticache subnet", subnet, exc)
def nuke(self) -> None: """Security groups delete function.""" for sec_grp in self.list_security_groups(): try: self.revoke_all_rules_in_security_group(sec_grp) except ClientError as exc: nuke_exceptions("security group rule", sec_grp, exc) for sec_grp in self.list_security_groups(): try: self.ec2.delete_security_group(GroupId=sec_grp) print("Nuke ec2 security group {0}".format(sec_grp)) except ClientError as exc: nuke_exceptions("security group", sec_grp, exc)
def nuke_launch_templates(self, time_delete: float) -> None: """Ec2 launche template delete function. Delete ec2 instances with a timestamp greater than time_delete :param int time_delete: The timestamp in seconds used from which the aws resource will be deleted """ for template in self.list_templates(time_delete): try: self.ec2.delete_launch_template(LaunchTemplateId=template) print("Nuke Launch Template{0}".format(template)) except ClientError as exc: nuke_exceptions("ec2 template", template, exc)
def nuke(self, older_than_seconds: float) -> None: """Ec2 snapshot deleting function. Delete all snapshot present on the current aws account. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for snapshot_id in self.list_snapshot(older_than_seconds): try: self.ec2.delete_snapshot(SnapshotId=snapshot_id) print("Nuke snapshot {0}".format(snapshot_id)) except ClientError as exc: nuke_exceptions("ec2 snapshot", snapshot_id, exc)
def nuke(self, older_than_seconds) -> None: """Glacier deleting function. Deleting all Glacier with a timestamp greater than older_than_seconds. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for vault in self.list_vaults(older_than_seconds): try: self.glacier.delete_vault(vaultName=vault) print("Nuke glacier vault {0}".format(vault)) except ClientError as exc: nuke_exceptions("glacier vault", vault, exc)
def nuke(self, older_than_seconds: float) -> None: """EFS deleting function. Deleting all efs with a timestamp greater than older_than_seconds. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for efs_file_system in self.list_file_systems(older_than_seconds): try: self.efs.delete_file_system(FileSystemId=efs_file_system) print("Nuke EFS share {0}".format(efs_file_system)) except ClientError as exc: nuke_exceptions("efs filesystem", efs_file_system, exc)
def nuke(self, older_than_seconds) -> None: """Ec2 ami deleting function. Deregister all ami present on the current aws account. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for ami_id in self.list_ami(older_than_seconds): try: self.ec2.deregister_image(ImageId=ami_id) print("Nuke ami {0}".format(ami_id)) except ClientError as exc: nuke_exceptions("ec2 ami", ami_id, exc)
def nuke(self, older_than_seconds: float) -> None: """Endpoint deleting function. Deleting all aws endpoint with a timestamp greater than older_than_seconds. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for endpoint in self.list_endpoints(older_than_seconds): try: self.ec2.delete_vpc_endpoints(VpcEndpointIds=[endpoint]) print("Nuke ec2 endpoint {0}".format(endpoint)) except ClientError as exc: nuke_exceptions("vpc endpoint", endpoint, exc)
def nuke_snapshots(self, time_delete: float) -> None: """Elasticache snapshot deleting function. Deleting elasticache snapshot with a timestamp lower than time_delete. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for snapshot in self.list_snapshots(time_delete): try: self.elasticache.delete_snapshot(SnapshotName=snapshot) print("Nuke elasticache snapshot {0}".format(snapshot)) except ClientError as exc: nuke_exceptions("elasticache snapshot", snapshot, exc)
def nuke(self, older_than_seconds: float) -> None: """Elastic Container Registry deleting function. Deleting all Elastic Container Registry with a timestamp greater than older_than_seconds. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for registry in self.list_registry(older_than_seconds): try: self.ecr.delete_repository(repositoryName=registry, force=True) print("Nuke ECR Registry{0}".format(registry)) except ClientError as exc: nuke_exceptions("ecr registry", registry, exc)
def nuke(self, older_than_seconds: float) -> None: """Kafka deleting function. Deleting all kafka cluster with a timestamp greater than older_than_seconds. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for cluster_arn in self.list_cluster(older_than_seconds): try: self.kafka.delete_cluster(ClusterArn=cluster_arn) print("Nuke kafka cluster {0}".format(cluster_arn)) except ClientError as exc: nuke_exceptions("kafka cluster", cluster_arn, exc)
def nuke_clusters(self, time_delete: float) -> None: """Elasticache cluster deleting function. Deleting elasticache cluster with a timestamp lower than time_delete. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for cluster in self.list_clusters(time_delete): try: self.elasticache.delete_cache_cluster(CacheClusterId=cluster) print("Nuke elasticache cluster {0}".format(cluster)) except ClientError as exc: nuke_exceptions("elasticache cluster", cluster, exc)
def nuke(self, older_than_seconds: float) -> None: """EKS cluster deleting function. Deleting all EKS clusters with a timestamp greater than older_than_seconds. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for cluster in self.list_clusters(older_than_seconds): try: self.eks.delete_cluster(name=cluster) print("Nuke EKS Cluster{0}".format(cluster)) except ClientError as exc: nuke_exceptions("eks cluster", cluster, exc)
def nuke(self, older_than_seconds: float) -> None: """Emr deleting function. Deleting all emr cluster resources with a timestamp greater than older_than_seconds. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for cluster_id in self.list_emr(older_than_seconds): try: self.emr.terminate_job_flows(JobFlowIds=[cluster_id]) print("Nuke emr cluster {0}".format(cluster_id)) except ClientError as exc: nuke_exceptions("emr cluster", cluster_id, exc)
def nuke(self, older_than_seconds: float) -> None: """Ebs deleting function. Deleting all ebs volumes resources with a timestamp greater than older_than_seconds. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for volume in self.list_ebs(older_than_seconds): try: self.ec2.delete_volume(VolumeId=volume) print("Nuke EBS Volume {0}".format(volume)) except ClientError as exc: nuke_exceptions("ebs volume", volume, exc)
def nuke(self, older_than_seconds: float) -> None: """Dlm policies deleting function. Deleting all dlm policy resources with a timestamp greater than older_than_seconds. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for policy in self.list_policy(older_than_seconds): try: self.dlm.delete_lifecycle_policy(PolicyId=policy) print("Nuke dlm Lifecycle Policy {0}".format(policy)) except ClientError as exc: nuke_exceptions("dlm policy", policy, exc)
def nuke_param_groups(self) -> None: """Redshift parameter group deleting function. Deleting redshift parameter groups with a timestamp lower than time_delete. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for param in self.list_cluster_params(): try: self.redshift.delete_cluster_parameter_group( ParameterGroupName=param) print("Nuke redshift param {0}".format(param)) except ClientError as exc: nuke_exceptions("redshift param", param, exc)
def nuke_subnets(self) -> None: """Redshift subnet deleting function. Deleting redshift subnets with a timestamp lower than time_delete. :param int older_than_seconds: The timestamp in seconds used from which the aws resource will be deleted """ for subnet in self.list_subnet(): try: self.redshift.delete_cluster_subnet_group( ClusterSubnetGroupName=subnet) print("Nuke redshift subnet {0}".format(subnet)) except ClientError as exc: nuke_exceptions("redshift subnet", subnet, exc)