Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to sync a single file to s3?

Tags:

amazon-s3

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

Is this possible or can only directories by synced?

like image 320
user48956 Avatar asked Nov 02 '13 18:11

user48956


People also ask

What happens if you upload the same file to S3?

It will overwrite the existing file. In case you want to have the previous file available, you need to enable versioning in the bucket.

How do I transfer files to S3 bucket?

To upload folders and files to an S3 bucketSign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that you want to upload your folders or files to. Choose Upload.

Can I use S3 as a file system?

Advantages of Mounting Amazon S3 as a File System Mounting an Amazon S3 bucket as a file system means that you can use all your existing tools and applications to interact with the Amazon S3 bucket to perform read/write operations on files and folders.


3 Answers

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'
like image 133
python1981 Avatar answered Nov 14 '22 15:11

python1981


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

like image 37
CodeBiker Avatar answered Nov 14 '22 14:11

CodeBiker


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'
like image 1
paopow Avatar answered Nov 14 '22 15:11

paopow