Skip to content

Instantly share code, notes, and snippets.

@alexpreynolds
Last active November 18, 2024 19:23
Show Gist options
  • Save alexpreynolds/f7a85b5f9519f3518b36ade026c383e2 to your computer and use it in GitHub Desktop.
Save alexpreynolds/f7a85b5f9519f3518b36ade026c383e2 to your computer and use it in GitHub Desktop.
Move list of AWS S3 objects in one bucket to a different storage class
#!/bin/bash
in_fn=${1}
aws_s3_bucket=${2}
aws_s3_dest_storage_class=${3}
while IFS= read -r line; do
aws_s3_key=$(echo "${line}" | cut -d' ' -f1)
aws_s3_path="s3://${aws_s3_bucket}/${aws_s3_key}"
echo "Moving [${aws_s3_path}] to storage class [${aws_s3_dest_storage_class}]"
aws s3 cp ${aws_s3_path} ${aws_s3_path} --storage-class ${aws_s3_dest_storage_class}
done < ${in_fn}
@alexpreynolds
Copy link
Author

To get a list of objects in the STANDARD storage class:

$ aws s3api list-objects --bucket ${bucket} --query 'Contents[?StorageClass == `STANDARD`].[Key,StorageClass]' --output text > ${bucket}.standard.txt

To move STANDARD objects to the INTELLIGENT_TIERING storage class:

$ ./aws_s3_move_storage_class.sh ${bucket}.standard.txt ${bucket} INTELLIGENT_TIERING
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment