Using Amazon Web Services and S3 For Cloud Computing

Posted By : Lokesh Babu Sharma | 22-Jan-2020

Introduction
Cloud computing enables enterprises to store and access data securely over the internet. By using cloud computing services, we can access data from the remote servers. Amazon web services (AWS) provides flexible, scalable, and easy-to-use environment for cloud computing solutions.

 

History
  • AWS services launched in 2002
  • Launched its cloud products in 2006
  • Holds first customer event in 2012
  • Reveals revenues achieved of $4.6 billion in 2015
  • Surpassed $10 billon revenue target in 2016
  • Release snowball and snowmobile in 2016
  • Offers nearly 100 cloud services in 2019
 

Some Important AWS Services
Load Balancing - Dynamically grow and shrink load balancing capacity as per traffic demands.
Amazon Cloud-front - optimized to deed with other aws such as Amazon EC2 and S3.
Security Management - provides security groups similar to an inbound network firewall.
Elastic Caches - provides the management of cache memory in cloud.
Amazon RDS (Relational Database Service) - provides database similar to MySQL, Oracle, MS SQL Server etc.
Storage & Backups - AWS provides S3 (Simple Storage Service) and store data as objects in S3 buckets.
Auto Scaling - AWS dynamically scale the web application as per traffic demands.

Architecture

 

S3 buckets (Simple Storage Service)
Amazon S3 stands for Simplle Storage Service that provide the utility to store  data as object in S3 buckets (cloud memory).
Amazon S3 is a most popular and in trends cloud stage service used by reputated companies.

 

Maven dependency

<dependency>
   <groupId>com.amazonaws</groupId>
   <artifactId>aws-java-sdk-s3</artifactId>
   <version>1.11.600</version>
</dependency>

 

How to use S3 Bucket (Java Snippet)
First we need to create AWS account
To calls AWS API actions we need to get AWS credentials.
We have to choose AWS region where we want save data objects.

 

Create AWS S3 client Connection

AWSCredentials credentials = new BasicAWSCredentials("<AWS accesskey>","<AWS secretkey>");

AmazonS3 amazonS3 =  AmazonS3ClientBuilder.standard()
                    .withCredentials(new AWSStaticCredentialsProvider(credentials))
                    .withRegion(Regions.US_EAST_2)
                    .build();

 

Create Bucket

String bucketName = "Name-Of-Bucket";
 
if(s3client.doesBucketExist(bucketName)) {
    LOG.info("Bucket name is not available."
      + " Try again with a different Bucket name.");
    return;
}
s3client.createBucket(bucketName);


Uploadng Objects

s3client.putObject(bucketName, "Document/hello.txt", new File("/Users/user/Document/hello.txt"));


List of Objects saved on S3 bucket

ObjectListing objectListing = s3client.listObjects(bucketName); 
for(S3ObjectSummary os : objectListing.getObjectSummaries()) {
    LOG.info(os.getKey());
}


Downloading Objects

S3Object s3object = s3client.getObject(bucketName, "picture/pic.png");
S3ObjectInputStream inputStream = s3object.getObjectContent();
FileUtils.copyInputStreamToFile(inputStream, new File("/Users/user/Desktop/hello.txt"));


Deleting Objects

s3client.deleteObject("baeldung-bucket","picture/pic.png");

 

Conclusion
Amazon AWS provides 99.99999999% durability and scalable storage eg. S3 bucket. It is easy to use.

About Author

Author Image
Lokesh Babu Sharma

Lokesh is in backend team. He Believes in smart work, He is good in programming. He loves to play with codes.He has expertise in Java.

Request for Proposal

Name is required

Comment is required

Sending message..