Cloud Storage using Amazon S3 - Direct file access using AWSCLI
This week, let's take a look at using Amazon S3.
In laymen's terms, Amazon S3 is an online cloud "cold storage service". It's usefulness comes from the fact that files stored here can be accessed through a variety of methods such as:
- Web Requests (HTTP directives)
- Fuse Filesystems
- Amazon's own AWSCLI
However, please note that S3 storage is only useful for cold storage, meaning storing files whose contents do not constantly change. This means it would be good for things such as, for example, RMAN backups and/or web page images. It WOULD NOT BE good for things such as Oracle data files/redo log files since these files are constantly in a state of flux.
Before we get into the tech details, make sure you have the following already setup.
- You have set up your AWS "Access Key" and "Access ID". (Click here if you have not done so)
- You have downloaded the AWSCLI and installed it on your machine. Its currently available for Macs/Linux and Windows. (Click here if you have not done so.)
Step 1: Create S3 Container (or Bucket)
Once you have finished with the items above, login into the AWS console and perform the following:
Click on the S3 Link: (Slide 1/6)
Create a new S3 Bucket (Slide 2/6)
Specify Bucket Name (Slide 3/6)
View/Edit Bucket Details(Slide 4/6)
View/Edit Access Details (Slide 5/6)
Commit S3 Changes (Slide 6/6)
Step 2: Configure AWSCLI
Once you are done with the S3 Bucket creation, you need to configure your AWSCLI installation. Perform the following in Terminal or a DOS SHELL.
Make sure you enter the correct region code which is defined in the S3 setup of the previous step. It is not always obvious what the AWS Region Code is with respect to its name, so here is a quick list that is accurate as of 8.2018. The region code that you will need to enter in the AWSCLI setup is in the first column.
||US GovCloud West
Step 3: Test AWS S3 Commands
Once you have correctly configured the AWSCLI, you should be all set to transfer files to/from S3. A brief overview of S3 commands is shown below.
|ls||List contents of a Bucket (prefix bucket with "s3://")|
Using this command w/o arguments will list all buckets
|aws s3 ls s3://mybucket|
aws s3 ls
|cp||Cp file/files to/from Bucket (prefix bucket with "s3://")||aws s3 cp myfile.txt s3://mybucket/myfile.txt|
aws s3 cp s3://mybucket/myfile.txt myfile.txt
|mv||Move file/files to/from Bucket (prefix bucket with "s3://").|
After the move is complete the file in the original location is removed
|aws s3 mv myfile.txt s3://mybucket/myfile.txt|
aws s3 mv s3://mybucket/myfile.txt myfile.txt
|rm||Remove file/files to/from Bucket (prefix bucket with "s3://")||aws s3 rm myfile.txt s3://mybucket/myfile.txt|
More information on S3 commands is available here.
Some examples are shown below:
That's basically it! While there are numerous cloud storage options available now, the ease of setup and use of S3 makes it particularly attractive to System Administrators whose free time is usually at a minimum. In addition the availability of "*nix like commands makes it extremely easy to integrate with automated processes.