Downloading objects from Amazon S3 using curl is a lightweight alternative to installing the full AWS CLI. Depending on your bucket's security settings, you can use curl for public objects, pre-signed URLs, or private objects using built-in AWS Signature Version 4 (SigV4) support. 1. Download a Public S3 Object
Since version 7.75.0, curl has native support for AWS Signature Version 4. This is the most efficient way to download private files securely without manual header calculation.
Always wrap the URL in quotes to prevent the shell from misinterpreting characters like & or ? . 3. Download Private Objects with Native SigV4 (Recommended) download s3 object using curl
A pre-signed URL grants temporary access to a private object without requiring the requester to have AWS credentials. You can generate these using the AWS CLI or an SDK, then use curl to fetch the file. curl -o "local-file-name" "https://amazonaws.com&..." Use code with caution.
: Use the region-specific endpoint https://[BUCKET].s3.[REGION].amazonaws.com/[FILE] for the best compatibility. 4. Advanced: Using Temporary Credentials Downloading objects from Amazon S3 using curl is
: Specifies the signing protocol. Replace [REGION] with your bucket's region (e.g., us-east-1 ).
If you are using temporary credentials (e.g., from an IAM Role or STS ), you must also include the session token in a header. Download a Public S3 Object Since version 7
If an object is public, you can download it using its direct Object URL . curl -O https://[BUCKET_NAME].s3.amazonaws.com/[OBJECT_KEY] Use code with caution. -O : Saves the file with its original remote name. -o [filename] : Saves the file with a custom name. 2. Download Using a Pre-signed URL
curl --user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" \ --aws-sigv4 "aws:amz:us-east-1:s3" \ -H "x-amz-security-token: $AWS_SESSION_TOKEN" \ "https://amazonaws.com" \ -O Use code with caution. Quick Troubleshooting Batch export files to Amazon S3 with cURL and AWS CLI
curl --user "ACCESS_KEY:SECRET_KEY" \ --aws-sigv4 "aws:amz:[REGION]:s3" \ "https://[BUCKET].s3.[REGION].amazonaws.com/[FILE_PATH]" \ -o [LOCAL_FILE_NAME] Use code with caution. --user : Your AWS Access Key and Secret Key.