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
aws s3 sync: Sync a Directory to S3 in CIaws s3 sync uploads only changed files to S3, making it ideal for static site deploys in CI. Learn the delete…
aws s3 ls: List S3 Buckets and Objects in CIaws s3 ls lists buckets, prefixes, and objects in S3. Learn the recursive, human-readable, and summarize flag…
aws cloudfront create-invalidation: Purge CDN in CIaws cloudfront create-invalidation purges cached paths from a CloudFront distribution after a deploy. Learn t…