2025-03-22
aws --profile <PROFILE> \
s3api list-objects-v2 \
--bucket <BUCKET> \
--endpoint-url https://<ACCOUNT_ID>.r2.cloudflarestorage.com
Three important steps to get this working:
--endpoint-url to point to your account on Cloudflare, and the R2 serviceCreate a profile for S3 usage. The easiest way to do this is with aws configure. Or, just edit the files in ~/.aws/config and ~/.aws/credentials.
Other calls I've made with the CLI to R2.
# use s3 ls instead of the s3api above
aws --profile <PROFILE> \
s3 ls s3://<PATH_ON_CLOUDFLARE> \
--endpoint-url https://<ACCOUNT_ID>.r2.cloudflarestorage.com
# uploading files
aws --profile <PROFILE> \
s3 sync \
<LOCAL_DIRECTORY_PATH> \
s3://<PATH_ON_CLOUDFLARE> \
--endpoint-url https://<ACCOUNT_ID>.r2.cloudflarestorage.com
I like to include the profile directly after the aws for better shell history search completion.
mitchell@gritts.me
Built by me. Writing and images are my original work unless otherwise noted. Please attribute this site when sharing.
This content served from this URL (mitchell.gritts.net) is licensed with the Unlicense. Content served from other URLs may have other licenses. The repo is currently private while I actively build out the site.