Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 52Cloud · AWS

How to copy files to and from S3

Backups, static websites, build artifacts, log exports, data for analytics — at work much of it goes through Amazon S3. The AWS CLI has two families: aws s3 (simple, like cp and rsync) and aws s3api (every API option). This how-to copies and syncs files safely (dry run first), encrypts them, shares one file for a limited time, and fixes the errors you will meet.

  • 5 Lessen
  • 3 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

52.1

The quick answer

aws s3 cp backup.tar.gz s3://acme-backups/web1/2026-11-19/
aws s3 cp s3://acme-backups/web1/2026-11-19/backup.tar.gz .
aws s3 sync ./dist s3://acme-site/ --delete --dryrun
aws s3 sync ./dist s3://acme-site/ --delete
aws s3 ls s3://acme-backups/web1/ --recursive --human-readable --summarize

Commando's in deze les

52.2

Step by step

  1. Log in and check the target (account, bucket, region):
aws sts get-caller-identity --query Account --output text
aws s3 ls s3://acme-backups/
  1. Copy single files or folders:
CommandDoes
aws s3 cp FILE s3://B/path/Upload one file.
aws s3 cp s3://B/path/FILE .Download one file.
aws s3 cp ./logs s3://B/logs/ --recursiveUpload a whole folder.
aws s3 mv s3://B/a s3://B/bMove or rename inside S3.
aws s3 rm s3://B/old/ --recursiveDelete (careful — check with --dryrun).
  1. Sync like rsync — only new and changed files. Always --dryrun before --delete:
aws s3 sync ./dist s3://acme-site/ --delete --dryrun
(dryrun) upload: dist/index.html to s3://acme-site/index.html
(dryrun) delete: s3://acme-site/old.js
aws s3 sync ./dist s3://acme-site/ --delete --exclude "*.map" --cache-control "max-age=300"
  1. Encrypt and choose the storage class (backups that are rarely read cost less in a colder class):
aws s3 cp db-2026-11-19.sql.gz s3://acme-backups/db/ --sse aws:kms --storage-class STANDARD_IA
  1. Share one file for a limited time — a pre-signed URL (no public bucket needed):
aws s3 presign s3://acme-backups/reports/q3.pdf --expires-in 3600

Anyone with the link can download for 1 hour — send it only to the right person.

  1. Big copies: large files are uploaded in parts automatically. Make it faster with more parallel requests:
aws configure set default.s3.max_concurrent_requests 20

52.3

Check that it worked

aws s3 ls s3://acme-backups/web1/2026-11-19/
2026-11-19 02:10:44   52428800 backup.tar.gz
aws s3 sync ./dist s3://acme-site/ --dryrun

The size matches the local file, and a second sync dry run lists nothing to do. For important backups, download one and test the restore.

Commando's in deze les

52.4

Common problems

ProblemCauseFix
An error occurred (AccessDenied)The role has no s3:PutObject/GetObject on that path, or a bucket policy blocks it.Check the profile; ask for access to that prefix only.
AccessDenied only with --sse aws:kmsNo rights on the KMS key.Add kms:Encrypt/kms:GenerateDataKey (and kms:Decrypt to read).
NoSuchBucketTypo, or another account.aws s3 ls; check the profile/account.
PermanentRedirect / wrong regionThe bucket is in another region.Add --region with the bucket's region.
--delete removed files you neededWrong source folder or missing slash.Always --dryrun first; turn on bucket versioning to undo deletes.
Upload is slowFew parallel requests, far region.max_concurrent_requests; a bucket in a near region.

Commando's in deze les

52.5

Go further

1What is the difference between aws s3 cp --recursive and aws s3 sync?

cp copies everything every time; sync copies only new and changed files (and with --delete also removes extra files).

2How do you give one person a file from a private bucket without making it public?

Commando's in deze les

Alle commando's in dit hoofdstuk