Today I Learned

Searching for files in AWS s3 from rails console

first set your credentials to AWS_ACCESS_KEY_ID, AWS_REGION, AWS_SECRET_ACCESS_KEY in .env

then

rails c
s3_client = Aws::S3::Client.new()

if credentials are set it will by default look for them there, but there is much more other options

then we can

s3_client.list_objects_v2(
    bucket: 'S3_BUCKET',
    max_keys: 'max_records by def 1000',
    prefix: 'some/key/to/file/'
  ).contents

It is good to note that prefix doesn’t begin from ‘/‘

also it works from ‘aws-sdk’ > 2.3.2