You don't "mount S3 buckets", they don't work that way for they are not filesystems. Amazon S3 is a service for key-based storage. You put objects (files) with a key and retrieve them back with the same key. The key is merely a name that you assign arbitrarily and you can include "/" markers in the names to simulate a hierarchy of files. For example, a key could be folder1/subfolder/file1.txt
. For illustration I show the basic operations with the java sdk.
First of all you must set up your amazon credentials and get an S3 client:
AWSCredentials credentials = new BasicAWSCredentials("your_accessKey", your_secretKey");
AmazonS3Client s3client = new AmazonS3Client(credentials);
Store a file:
File file = new File("some_local_path/file1.txt");
String fileKey = "folder1/subfolder/file1.txt";
s3client.putObject("bucket_name", fileKey, file);
Retrieve back the file:
S3ObjectInputStream objectInputStream = s3client.getObject("bucket_name", fileKey).getObjectContent();
You can read the InputStream or you can save it as file.
List the objects of a (simulated) folder: See my answer in another question.