javaamazon-web-servicesamazon-s3amazon-ec2ec2-api-tools

Using Java SDK (AWS) to programmatically connect S3 to EC2 as a filesystem


I am trying to use java sdk to create a local filesystem on an EC2 machine which would actually be a S3 resource

I have already written code to start EC2 machine, create security groups, keys etc but now want to mount a S3 on top of that EC2 machine that I create using java SDK. There seems to be no detailed solution online.


Solution

  • First, you should prepare your own AMI with s3fs pre-installed. See https://forums.aws.amazon.com/thread.jspa?threadID=39361. The EC2 instance should be started from this custom AMI.

    Second, right after the instance is up and running, you should establish an SSH connection to it and run

    /usr/bin/s3fs bucketname /mnt/mountpoint
    

    I would recommend to use JSch