Copying files from EC2 server to an S3 bucket

You can copy the files from your EC2 server to an S3 bucket via AWS CLI in following way:

  • SSH into your EC2 instance
  • Configure AWS CLI on your EC2 instance
$ aws configure
  • Make sure the EC2 instance has a role assigned which has permissions to read and write to S3 bucket
  • Try running below command in CLI to access and check if you have access to S3 bucket
$ aws s3 ls s3://mybucket/
  • If connect is there and you can see existing files listed then go ahead and copy files from ec2 to s3 with below command
$ aws s3 cp test.txt s3://mybucket/test2.txt

//copying file with an expiration date
$ aws s3 cp test.txt s3://mybucket/test2.txt --expires 2014-10-01T20:30:00Z 

Hope this helps! Let me know in the comments if you have any issues!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s