Attach And Mount EBS Volume To EC2 Linux Instance

AWS allows to create / attach / mount new EBS volumes to instances for extra storage. Use lsblk command to view available disk devices and other mount points.

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 8.0G 1.6G 6.5G 20% /

– Go to EC2 Console –> Volumes to create new volume of required size and type.

– Select the last created volume and select the “attach volume” to attach to the ec2 instance.

– Now, SSH login to ec2 instance and find list of available disks or mounts.

# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 8G 0 disk
└─xvda1 202:1 0 8G 0 part /
xvdf 202:80 0 16G 0 disk

Check the volume has data or empty
# file -s /dev/xvdf

Format the volume to ext4 file system type
# mkfs -t ext4 /dev/xvdf

Mount the volume to “/mnt/dir/” directory
# mkdir /mnt/dir/
# mount /dev/xvdf /mnt/dir/ -t ext4

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 8.0G 1.6G 6.5G 20% /
/dev/xvdf 16G 45M 15G 1% /mnt/dir

# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 8G 0 disk
└─xvda1 202:1 0 8G 0 part /
xvdf 202:80 0 16G 0 disk /mnt/dir

EBS Automount On Reboot using fstab
# cp /etc/fstab /etc/fstab.bak

Write FSTAB file
# vi /etc/fstab
/dev/xvdf /mnt/dir ext4 defaults,nofail

Check errors
# mount -a

How to unmount volume??
# umount /dev/xvdf

Help: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html

SaaS built using a PaaS (Google App Engine) and using IaaS (Amazon EC2)

SaaS = PaaS + IaaS

Historical Method - VaR Cloud App.png

Tools for Development, Testing and Implementation:
* Amazon Web Services (AWS)
* Google App Engine (GAE)
* Google Chart Libraries
* Eclipse IDE

VaR Cloud Presentation SVNLabs

References:
Google AppEngine: http://code.google.com/appengine/
Amazon EC2: http://aws.amazon.com/ec2/
Google Chart: http://code.google.com/apis/chart/

“A lamp does not speak. It introduces itself through it’s light. Achievers never expose themselves. But their achievements expose them..!!!”

JSP S3Upload

JavaScript is good alternative to bypass AWS bucket policies 😉

<%@ include file="config.jsp" %>
<%@page import="java.util.Calendar"%>
<%@page import="java.util.Date"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<title>S3 Upload - JSP Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<script src="sha1.js"></script>
<script src="webtoolkit.base64.js"></script>
<script src="script.js"></script>

<script>

function uploadS3()
{
var awsid = '<%=awsAccessKey %>';
var awskey = '<%=awsSecretKey %>';

var fileField = document.getElementById("file").value;

var policyText = '{"expiration": "2015-01-01T12:00:00.000Z","conditions": [{"bucket": "<%=bucket %>" },{"acl": "<%=acl %>" },["eq", "$key", "'+fileField+'"],["starts-with", "$Content-Type", "text/"],]}'; 

var policyBase64 = Base64.encode(policyText);

var signature = b64_hmac_sha1(awskey, policyBase64);

document.getElementById("policy").value = policyBase64;
document.getElementById("signature").value = signature;
document.getElementById("key").value = fileField;

//document.getElementById("postform").submit();

document.getElementById("result").innerHTML = '<a href="http://s3.amazonaws.com/<%=bucket %>/'+fileField+'">http://s3.amazonaws.com/<%=bucket %>/'+fileField+'</a>'; 

}

</script>

</head><body>

<strong>Uploading to Amazon S3</strong>

<div class="main">

<p>

<form id="postform" action="http://s3.amazonaws.com/<%=bucket %>" method="post" onsubmit="return uploadS3();" enctype="multipart/form-data">
<input type="hidden" name="key" id="key" value="" />
<input type="hidden" name="acl" id="acl" value="<%=acl %>" />
<input type="hidden" name="content-type" id="content-type" value="text/plain" />
<input type="hidden" name="AWSAccessKeyId" id="AWSAccessKeyId" value="<%=awsAccessKey %>" />
<input type="hidden" name="policy" id="policy" value="" />
<input type="hidden" name="signature" id="signature" value="" />
<input name="file" id="file" type="file" />
<input name="submit" value="Upload" type="submit" />
</form>

<div id="result"></div>

</p>
</div>

</body></html>
PHP based S3 Upload Tool: http://svnlabs.com/demo/s3/

You are great if you can find your faults, Greater if you can correct them, But greatest if you accept others with their faults.

fbsocialmarketing.com

FB Social Marketing is a Social Media Marketing company specializing in the development of Facebook Fan Pages for your business.

Be sure to check out complete line of training videos.

I have partnered with Shelle Kind of fbsocialmarketing.com and we have released the Amazon S3 / EC2 Solution for Facebook fanpage apps.

How to Setup Elastic Load Balancing on AWS