Skip to content

Instantly share code, notes, and snippets.

@kuu
Created September 2, 2019 06:02
Show Gist options
  • Save kuu/16a30453ebcec8ce9d073a7ec6e2a662 to your computer and use it in GitHub Desktop.
Save kuu/16a30453ebcec8ce9d073a7ec6e2a662 to your computer and use it in GitHub Desktop.
CLI for delete all objects in MediaStore container
#!/usr/bin/python
import sys
import subprocess
import json
args = sys.argv
def deleteObject(endpoint, path, name):
print ('deleteObject("{0}", "{1}", "{2}"))'.format(endpoint, path, name))
res = subprocess.check_output(['aws', 'mediastore-data', 'delete-object', '--endpoint', endpoint, '--path', path + '/' + name])
def deleteFolder(endpoint, path):
print ('deleteFolder("{0}", "{1}"))'.format(endpoint, path))
res = subprocess.check_output(['aws', 'mediastore-data', 'list-items', '--endpoint', endpoint, '--path', path])
obj = json.loads(res)
for item in obj['Items']:
if item['Type'] == 'OBJECT':
deleteObject(endpoint, path, item['Name'])
elif item['Type'] == 'FOLDER':
deleteFolder(endpoint, path + '/' + item['Name'])
def deleteContainer(name):
print ("Delete all objects in '" + name + "'")
res = subprocess.check_output(['aws', 'mediastore', 'list-containers'])
obj = json.loads(res)
for container in obj['Containers']:
if container['Name'] != name:
continue
deleteFolder(container['Endpoint'], '')
for arg in args[1:]:
deleteContainer(arg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment