LoginSignup
3
0

More than 3 years have passed since last update.

AWS MediaStore のファイルを全部消す方法

Last updated at Posted at 2019-01-11

新年明けましておめでとうございます。

新年早々、ネタを用意できない streampack 木村です。
そんな訳で今回は小ネタを。

MediaStore のファイル削除

ところで皆さん、MediaStore のファイルを消すの面倒じゃありませんか?
S3 みたいに一括処理ができないので、今の所一つ一つシコシコ消す以外に方法がありません。

ご存知の方も多いかもしれませんが、AWS のフォーラムで AWS CLI と awk コマンドと組み合わせた一括削除コマンドが上がっております。

aws mediastore-data list-items --endpoint=your endpoint -—path=path to files | awk ‘{system(“aws mediastore-data delete-object --endpoint=your endpoint --path=path to files"$6)}'

How to delete all items (eg, empty container)?
https://forums.aws.amazon.com/thread.jspa?messageID=829906&tstart=0

your endpointpath to files をあなたの環境に合わせて叩くと全部消してくれます。

シェルスクリプト

上記でも良いのですが毎回コマンド叩くのも面倒なのでスクリプト化しました。


#!/bin/sh

epoint="your endpoint"
path="path to files"

aws mediastore-data list-items --endpoint=$epoint --path=/$path --output=text | awk '{system("aws mediastore-data delete-object --endpoint='"${epoint}"' --path=/'"${path}"'/"$6)}'

簡単ですみません・・・
今回は以上!

2019/3/7 追記

profileregionも変数化しました。


#!/bin/sh

epoint="your endpoint"
path="path to files"
region="ap-northeast-1"
profile="your profile"

aws mediastore-data list-items --region=$region --profile $profile --endpoint=$epoint --path=/$path --output=text | awk '{system("aws mediastore-data delete-object --endpoint='"${epoint}"' --profile '"$profile"' --region='"$region"' --path=/'"${path}"'/"$6)}'
3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0