Skip to content
Latchkey

aws s3 cp: Copy Files to S3 in CI

Copy individual files or whole directories between local disk and S3.

aws s3 cp copies objects between the local filesystem and S3 (or between buckets). In CI it is the workhorse for uploading build artifacts, static sites, and release bundles. With --recursive it copies an entire directory tree.

Common flags

  • --recursive - copy a directory tree
  • --exclude / --include - filter which files are copied (order matters)
  • --acl public-read - set a canned ACL on uploaded objects
  • --content-type - override the guessed MIME type
  • --cache-control - set caching headers for static assets

Example in CI

Upload a build directory after a job runs on a CI runner.

shell
aws s3 cp ./dist s3://my-bucket/app --recursive --cache-control "max-age=31536000"

Common errors in CI

  • Unable to locate credentials - configure the OIDC role in your workflow
  • An error occurred (AccessDenied) - IAM policy lacks s3:PutObject on the target prefix
  • The specified bucket does not exist - wrong bucket name or region
  • An error occurred (AccessControlListNotSupported) - bucket has ACLs disabled; drop --acl

Key takeaways

  • aws s3 cp moves files to/from S3; add --recursive for directories.
  • Use --exclude/--include to filter and --cache-control for static assets.
  • AccessDenied almost always means a too-narrow s3:PutObject IAM policy.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →