-
-
Save iShiBin/670264c1f1d2a5ff6b5fc160c46ad504 to your computer and use it in GitHub Desktop.
List of files in a specific AWS S3 location in a shell script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# setup AWS CLI first | |
# http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-set-up.html | |
# configure AWS CLI (e.g. use IAM role for S3 access) | |
export AWS_DEFAULT_REGION=us-east-1 | |
export AWS_ACCESS_KEY_ID=IDHERE | |
export AWS_SECRET_ACCESS_KEY=KeyHere | |
# s3 ls command | |
# http://docs.aws.amazon.com/cli/latest/reference/s3/ls.html | |
# space-separated string (contains dates etc.) | |
flist=$(aws s3 ls s3://bucket.name/directory/path/) | |
# file list as an array | |
flist=(`aws s3 ls s3://bucket.name/directory/path/ | awk '{print $4}'`) | |
# first element | |
echo $flist | |
# NOTE: indexing starts with 0 | |
echo ${flist[0]} | |
# all elements | |
# http://stackoverflow.com/questions/15224535/bash-put-list-files-into-a-variable-and-but-size-of-array-is-1 | |
echo ${flist[@]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment