Canarys | IT Services


Introduction to Amazon S3 (Simple Storage Service) and EC2 (Elastic Cloud Computing) in Asp.Net


S3 is an Internet storage engine which has to be designed to make job easier for developers.

Developers can upload, manage and control access to data that is stored on Amazon’s Servers through simple API’s which are provided by Amazon and Other third party Components.

It’s a highly flexible, scalable, reliable, fast, and inexpensive storage infrastructure

It lets users to store unlimited number of objects up to 5GB free for single account.

On the Other side Users has to pay monthly charges for what they consume.

How to Configure Amazon S3 account:

Amazon allow users to sign-up for free and use 5GB of data space.

To create new account, you can log on to and signup.

Note: Please make sure that users should share their card details for creating account.

Objects in S3:

Bucket: It is the place where all your data gets stored. It simply acts as container for your data. All files/folders whatever created that are stored in Buckets.

Once Create Amazon Account and redirect to link Console will look like below


Configuring Amazon S3 Client in Asp.Net:

Once Aws.Net Tools that are downloaded from Amazon Website are installed in windows machine. Automatically some predefined AWS Templates are installed in VS2012 as shown in below.


Uploading files to S3 using

1 Open VS2012àNew Project à Templates à C# à Web à Asp.Net Web Forms Application à Solution Name as needed


2 Add AWSSDK.dll reference to project.

3. Web.Config Configuration Settings specified below

4. Sample Code to upload file to Amazon S3 server.

using System;

using System.Collections.Generic;

using System.Configuration;

using System.IO;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using Amazon;

using Amazon.EC2;

using Amazon.S3;

using Amazon.S3.Model;

using Amazon.S3.Transfer;

namespace AmazonS3POC


public partial class Sample : System.Web.UI.Page


string accessKey = ConfigurationManager.AppSettings[“AWSAccessKeyId”];

string secretKey = ConfigurationManager.AppSettings[“AWSSecretKey”];

protected IAmazonS3 s3;

protected void Page_Load(object sender, EventArgs e)


if (!Page.IsPostBack)

s3 = AWSClientFactory.CreateAmazonS3Client();

//Create  samplefolder to gurugpackages bucket.

CreateFolder(“gurugpackages”, “samplefolder”);


public void CreateFolder(string bucket, string folder)



var key = string.Format(@”{0}/”, folder);

var request = new PutObjectRequest() { BucketName = (bucket), Key = (key) };

request.InputStream = new MemoryStream();




protected void btnUpload_Click(object sender, EventArgs e)



if (fup1.PostedFile.ContentLength > 0) // accept the file


//Saving file to server.

PutObjectRequest request = new PutObjectRequest();

request.Key = Path.GetFileName(fup1.PostedFile.FileName);

request.InputStream = (fup1.PostedFile.InputStream);

request.BucketName = “gurugpackages”;

request.CannedACL = S3CannedACL.PublicReadWrite;

request.StorageClass = “STANDARD”;







Amazon EC2 Instance:

Amazon EC2 (Elastic Compute Cloud) instance that is configured under EC2 console from Amazon website acts like virtual server for deploying our applications. For each instance which comes from free size of 30GB, amazon priced approximately $0.1 / day.

Note: Uploading files from our local server to Amazon S3 is slow compared to EC2 to S3 because both EC2 and S3 are Amazon servers.

These are a few basic programming on S3 which I like to share with the developers. More information on Amazon S3 implementation to be coming soon.

Leave a Reply

Your email address will not be published. Required fields are marked *

Reach Us

With Canarys,
Let’s Plan. Grow. Strive. Succeed.