Code Robo
Formatter
Comparator
Tester
Merger
Converter
Utility
Java Code Complience
Validator
EncoderDecoder
Virtual Service
Java Code To Connect Amazon Glacier Service
       Talk to EasyAssistant

It provides the steps to connect AWS Glacier service and create vault, delete vault, upload zip file to vault and download files from Glacier valuts. One sample example with java code is shown for Java platform using AWS JAVA SDK library. Sample code uses aws-java-sdk-1.0.12 library provided by AWS. This java code is very sort and simple so that user can understand easily.


This java code connect AWS S3 Glacier service and get the list of the Vaults and create a new valut . Downloading and uploading zip files to the S3 valult is very common requirement. It can be done just extending the current prgram. From my experience what I noticed that people face the main challenge to coneect the S3 service from Java client. But once the able to connect, they can easy upload and download files. This program will guide you on how to connect Glacier service from thrid part (external) program / service to manage the resources in AWS glacier service. This code can be copied, compiled and run on eclipse or any other Java IDE.

Sample Java Code To Connect S3 Glacier Service:

package easycodeforall.client;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.glacier.AmazonGlacierClient;
import com.amazonaws.services.glacier.model.CreateVaultRequest;
import com.amazonaws.services.glacier.model.CreateVaultResult;
import com.amazonaws.services.glacier.model.DescribeVaultOutput;
import com.amazonaws.services.glacier.model.ListVaultsRequest;
import com.amazonaws.services.glacier.model.ListVaultsResult;

public class ConnectAWSGlacier {

	public static void main(String[] args) {

		System.out.println("Conneting AWS Amazon  Glacier Service");
		String newValutName = "easycodeforallVault";
		String accessKeyID = "AKIAY35*********JB37";// You get it form AWS Console /
		// You get it form AWS Console
		String secretAccessKey = "MysMOFS*********************qdscLSaV";
		AWSCredentials awsCredentials = new BasicAWSCredentials(accessKeyID, secretAccessKey);

		AmazonGlacierClient glacierClient = new AmazonGlacierClient(awsCredentials);
		String region = "ap-south-1"; // Mumbai region
		glacierClient.setEndpoint("https://glacier." + region + ".amazonaws.com/");

		String accountID = "61********74";
		// You will get this value from AWS console.or put hyphen. hyphen means
		// assocaitated account
		ListVaultsRequest listRequest = new ListVaultsRequest(accountID);
		// associated with the credentials
		ListVaultsResult vaultList = glacierClient.listVaults(listRequest);

		for (DescribeVaultOutput vault : vaultList.getVaultList()) {
			System.out.println("----");
			System.out.println("VaultName:" + vault.getVaultName() + "| CreateDate :" 
			+ vault.getCreationDate());
		}

		CreateVaultRequest createVaultRequest = new CreateVaultRequest();
		createVaultRequest.setVaultName(newValutName);
		CreateVaultResult result = glacierClient.createVault(createVaultRequest);
		System.out.println("Creation Request=" + result.getSdkResponseMetadata());
		System.out.println("--------AWS S3 GLACIER CONNECTION DONE.-------");

	}

}



Now question is how we can get the accessKeyID and secretAccessKey


1. Create a Policy for Glacier service as shown below.
Create Policy To Access Glacier Service


2. Create a IAM User along with accessKey to access Glacier service as shown below Once you attach a policy, it will ask you to create a access key. Just click on that, it will create the access key and secret key.

Create user and access key, secret key


3. Assign the policy to the user which you created in the above step

Attach Policy With the User

Please provide your feedback here
It has been explained in this video (https://youtu.be/bxkNb0GuELY). Please watch it.
 



Post Your Comment:
Name :
Email ( Optional) :
Comments / Suggestion (* Required) It is required: :
: