How to use AWS S3 CLI to dump files to stdout in BASH?

蓝咒 提交于 2019-11-30 01:06:57

dump the contents of all of the file objects to stdout.

You can accomplish this if you pass - for destination of aws s3 cp command. For example, $ aws s3 cp s3://mybucket/stream.txt -.

What you're trying to do is something like this? ::

#!/bin/bash

BUCKET=YOUR-BUCKET-NAME
for key in `aws s3api list-objects --bucket $BUCKET --prefix bucket/path/to/files/ | jq -r '.Contents[].Key'`
do
  echo $key
  aws s3 cp s3://$BUCKET/$key - | md5sum
done

If you are using a version of the AWS CLI that doesn't support copying to "-" you can also use /dev/stdout:

$ aws s3 cp --quiet s3://mybucket/stream.txt /dev/stdout

You also may want the --quiet flag to prevent a summary line like the following from being appended to your output:

download: s3://mybucket/stream.txt to ../../dev/stdout

You can try using s3streamcat, it supports bzip, gzip and xz formats as well.

Install with

sudo pip install s3streamcat

Usage:

s3streamcat s3://bucketname/dir/file_path
s3streamcat s3://bucketname/dir/file_path | more
s3streamcat s3://bucketname/dir/file_path | grep something

Ah ha!

https://pypi.python.org/pypi/s3cat/1.0.8

I'm writing more characters to satisfy the length requirement.

If you wish to accomplish this using BASH, you'll have to call-out to an external app such as the AWS Command-Line Interface (CLI). It does not have a CAT equivalent, so you would need to copy the file locally and then CAT it.

Alternatively, you could use/write an app that directly calls the AWS SDK, which is available for languages such as Python, PHP, Java. By using the SDK, file contents can be retrieved in-memory and then sent to stdout.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!