2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

S3に空ディレクトリを掘るだけというしょっぱいスクリプト

Last updated at Posted at 2017-12-28

S3にディレクトリなどないと何度言ry

aws s3 コマンドの cpsync はなぜか空のディレクトリを作成しない。
新規のバケットでディレクトリ構成を初期化するのに困る。

S3に空のディレクトリを作成するシェルスクリプト

s3mkdirp.sh
# !/bin/bash
set -e
S3API="/usr/bin/aws s3api"
# export AWS_ACCESS_KEY_ID=
# export AWS_SECRET_ACCESS_KEY=
# export AWS_DEFAULT_REGION=ap-northeast-1

if [ $# -lt 2 ]
then
  echo "Usage:  ${0} bucket dir [dir ...]"
  exit 1
fi

BUCKET=$1
shift

S3WK=/tmp/s3/$BUCKET
mkdir -p $S3WK
cd $S3WK
mkdir -p $@

for d in $(find * -type d)
do
  echo ${d}
  $S3API put-object --bucket $BUCKET --key ${d}/
done
cd - > /dev/null
rm -rf $S3WK

使い方は、最初の引数でバケット名を指定し、以降の引数でディレクトリ名を指定する。

$ ./s3mkdirp my.bucket.name aaa bbb/ccc/{ddd,eee}

バケット名に s3:// など付けない
ディレクトリ名にルートの / など付けない。ていうか付けないで、おねがい。

途中階層も含め、すべてのディレクトリに対するオブジェクトが作成される

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?