def s3_cleanup(bucket, session):
 region = 'us-west-2'
 client = session.create_client('s3', region_name=region)
 try:
  client.head_bucket(Bucket=bucket)
 except ClientError:
  return
 response = client.list_objects(Bucket=bucket)
 contents = response.get('Contents', {})
 keys = [content['Key'] for content in contents]
 for key in keys:
  client.delete_object(Bucket=bucket, Key=key)
 client.delete_bucket(Bucket=bucket)

def s3_cleanup ( bucket , session ) : region = 'us-west-2' client = session . create_client ( 's3' , region_name = region ) try : client . head_bucket ( Bucket = bucket ) except ClientError : return response = client . list_objects ( Bucket = bucket ) contents = response . get ( 'Contents' , { } ) keys = [ content [ 'Key' ] for content in contents ] for key in keys : client . delete_object ( Bucket = bucket , Key = key ) client . delete_bucket ( Bucket = bucket )
function to cleanup generated s3 bucket and files .