24Nov

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 http://aws.amazon.com/s3/ 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 https://console.aws.amazon.com/s3/home?region=us-west-2#. Console will look like below

S3bucket

 

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.

S3Asp.

Uploading files to S3 using asp.net:

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

Sample

 

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();

                s3.PutObject(request);

          

        }

        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";

 

                    s3.PutObject(request);

                }

            }

       }

    }

}

 

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.

  

Related

Token Based Authentication for Web API's

Securing ASP.NET Web API using Custom Token Based AuthenticationProviding a security to the Web API&...

Read More >

ASP.NET: Audit Trail Implementation using Entity Framework

When you are working with certain projects which involves the Customer records, you might need to tr...

Read More >

Dependency Injection on SignalR

                &nbs...

Read More >

Create custom project templates in Visual Studio

Visual studio installation comes with the various predefined project templates, and we can use one o...

Read More >

Part 2 of KnockOut.js in Asp.Net

Computed Observables:             &...

Read More >

Introduction on SignalR

Introduction on SignalRReal–Time Web ApplicationThe real-time web is a set of technologies tha...

Read More >

How to upload documents to SharePoint 2013

IntroductionSharePoint is a browser-based collaboration, content management, and extensible platform...

Read More >

Introduction to KnockOut.Js in Asp.Net

What is KnockOut.Js?Knockout.Js (simply KO) is a powerful JavaScript library which allows developers...

Read More >

How to use Model Binding with ASP.NET Data Controls

IntroductionASP.NET 4.5 provides a flexible alternative to server data controls called as, Model Bin...

Read More >

Using XMPP and Openfire server in ASP.NET C# - Part -2

Roster in XMPPRoster are the contacts of  user (contact list). Roster Handlers in AgsXmppL...

Read More >

Share

Comments

Enjoyed reading the article above really explains everything in detail,the article is very interesting and effective.Thank you and good luck for the upcoming articles.Simply want to say your article is as amazing. Thank you a million and please continue this great work..
2/19/2020 7:05:59 PM | Reply
Great Post for Beginner to understand amazon web service . Thank you for your post . I really enjoyed reading your blog.it gives valuable information and new idea about aws . it will help me to learn new concepts in aws Keep posted article like this.
1/21/2020 6:06:08 PM | Reply

Post a Comment

  • Recent
  • Popular
  • Tag
Tags
Monthly Archive
Subscribe
Name

Contact Us
  • *
  • *