user48956
user48956

Reputation: 15810

Is it possible to sync a single file to s3?

I'd like to sync a single file from my filesystem to s3.

Is this possible or can only directories by synced?

Upvotes: 41

Views: 24404

Answers (4)

pythonjsgeo
pythonjsgeo

Reputation: 5411

Use include/exclude options for the sync-directory command:

e.g. To sync just /var/local/path/filename.xyz to S3 use:

s3 sync /var/local/path s3://bucket/path --exclude='*' --include='filename.xyz'

Upvotes: 56

paopow
paopow

Reputation: 21

Just to comment on pythonjsgeo's answer. That seems to be the right solution but make sure so execute the command without the = symbol after the include and exclude tag. I was including the = symbol and getting weird behavior with the sync command.

s3 sync /var/local/path s3://bucket/path --exclude '*' --include '*/filename.xyz'

Upvotes: 2

CodeBiker
CodeBiker

Reputation: 3263

cp can be used to copy a single file to S3. If the filename already exists in the destination, this will replace it:

aws s3 cp local/path/to/file.js s3://bucket/path/to/file.js

Keep in mind that per the docs, sync will only make updates to the target if there have been file changes to the source file since the last run: s3 sync updates any files that have a size or modified time that are different from files with the same name at the destination. However, cp will always make updates to the target regardless of whether the source file has been modified.

Reference: AWS CLI Command Reference: cp

Upvotes: 18

Paul
Paul

Reputation: 1348

You can mount S3 bucket as a local folder (using RioFS, for example) and then use your favorite tool to synchronize file(-s) or directories.

Upvotes: -1

Related Questions