Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to upload files to Amazon S3 using an access key id and secret access key

I have to upload some static HTML and CSS files to Amazon S3, and have been given an Access Key ID as well as a Secret Access Key.

I've signed up for AWS, how to I upload stuff?

like image 511
Qasim Avatar asked May 21 '14 13:05

Qasim


2 Answers

If you are comfortable using the command line, the most versatile (and enabling) approach for interacting with (almost) all things AWS is to use the excellent AWS Command Line Interface (AWS CLI) - it meanwhile covers most services' APIs, and it also features higher level S3 commands that ease dealing with your use case considerably, see the AWS CLI reference for S3 (the lower level commands are in s3api) - specifically you are likely interested in:

  • cp - Copies a local file or S3 object to another location locally or in S3
  • sync - Syncs directories and S3 prefixes.

I use the latter to deploy static websites hosted on S3 by simply syncing what's changed, convenient and fast. Your use case is covered by the first of several Examples (more fine grained usage with --exclude, --include and prefix handling etc. is available):

The following sync command syncs objects under a specified prefix and bucket to files in a local directory by uploading the local files to s3. [...]

aws s3 sync . s3://mybucket

While the AWS CLI supports the regular AWS Credentials handling via environment variables, you can also configure Multiple Configuration Profiles for yourself and other AWS accounts and switch as needed:

The AWS CLI supports switching between multiple profiles stored within the configuration file. [...] Each profile uses different credentials—perhaps from two different IAM users—and also specifies a different region. The first profile, default, specifies the region us-east-1. The second profile, test-user, specifies us-west-2. Note that, for profiles other than default, you must prefix the profile name with the string, profile.

like image 152
Steffen Opel Avatar answered Sep 22 '22 12:09

Steffen Opel


Assuming you want to upload to S3 storage, there are some good free apps out there. If you google for "CloudBerry Labs" they have a free "S3 Explorer" application which lets you drag and drop your files to your S3 storage. When you first install and launch the app, there will be a place to configure your connection. That's where you'll put in your AccessKey and SecretKey.

like image 21
Dennis Frandsen Avatar answered Sep 19 '22 12:09

Dennis Frandsen