0
0

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 3 years have passed since last update.

S3バケットのオブジェクトを1000個以上取得する

Last updated at Posted at 2020-03-24

公式リファレンスに記載があるように、list_objects_v2は1000個以上のS3オブジェクトを取得する際には面倒なnext_tokenの処理が必要になります。

そこで、1000個以上のS3オブジェクトを扱う際には、Aws::S3::Bucket#objectsを使うと、このようにシンプルに書けます。

list-objects.rb

require 'aws-sdk'
bucket = Aws::S3::Bucket.new('<バケット名>')
obj_array = bucket.objects.map(&:key)

obj_array.size	# => オブジェクト数
obj_array.first	# => プレフィックス/オブジェクト名

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?