The cloud is here, and there’s a lot more to it than just scaling servers up and down. New paradigms have emerged from cloud services that enable you to break down complex problems into much simpler solutions. With new tools and techniques, yesterday’s monstrous enterprise applications can be replaced by scalable and cheaper cloud applications of tomorrow. In this session you will see the architecture of a large enterprise application dissected into its components: web services, storage of both structured and non-structured data, message queuing and delivery, and notifications. With the availability of developer-friendly APIs, it is easier than ever before to leverage the many cloud services offered by Amazon Web Services.
2. ONDREJ BALAS
Microsoft MVP in C#
Writer for Visual Studio Magazine
Owner of UseTech Design (est. 2001)
Building software that drives business
Serial Entrepreneur
WWW.ONDREJBALAS.COM
ONDREJ@ONDREJBALAS.COM
@ONDREJBALAS
16. Virtual Machines
Provisioned within minutes
Choose your own AMI (disk image) or use a pre-existing one
Pay by the hour – Linux as low as $0.003 per hour
or Windows for $0.006 per hour
Many machine sizes to choose from
19. EC2 Instance
AMI
When an EC2 Instance
is created, its hard disk
contents are copied
from an AMI
Internet
Security Group
A security group acts
as the firewall between
the internet and the
instance
An AMI can be created
by copying the current
state of an EC2 instance
20. EC2 Instance
AMI
When an EC2 Instance
is created, its hard disk
contents are copied
from an AMI
Internet
Security Group
A security group acts
as the firewall between
the internet and the
instance
Key Pair
An instance is assigned a key pair at
creation time, and the same one must be
later used to gain access to the instance.
27. Worker Service
Installed onto my Base AMI
Updateable from the Instrumentation
Uses WebAPI Selfhost to manage requests
And TopShelf to make it a service
29. SQS (Simple Queue Service)
Queue ConsumerPublishers
Publishers send
messages to the queue
Consumer periodically checks
the queue for messages
30. SQS (Simple Queue Service)
Consumer
Consumer watches for
messages
QueuePublishers
Publishers send
messages to the queue
Consumer controls throughput
by only sending one write at a
time to the database
Database
31. SQS (Simple Queue Service)
Queue ConsumersPublishers
Publishers send
messages to the queue
Consumers take messages
from the queue and process
them in parallel
33. SQS (Simple Queue Service)
Writing to a queue
AmazonSQSClient client = new AmazonSQSClient(credentials, RegionEndpoint.USEast1);
string message = "my message";
string queueUrl = "https://sqs.us-east-1.amazonaws.com/025631894481/aws-talk";
SendMessageResponse sendMessageResponse = client.SendMessage(queueUrl, message);
34. SQS (Simple Queue Service)
Reading from a queue
AmazonSQSClient client = new AmazonSQSClient(credentials, RegionEndpoint.USEast1);
string queueUrl = "https://sqs.us-east-1.amazonaws.com/025631894481/aws-talk";
ReceiveMessageResponse response = client.ReceiveMessage(queueUrl);
foreach (Message message in response.Messages)
{
// Do something with the message
client.DeleteMessage(queueUrl, message.ReceiptHandle);
}
35. SQS (Simple Queue Service)
Reading from a queue
AmazonSQSClient client = new AmazonSQSClient(credentials, RegionEndpoint.USEast1);
string queueUrl = "https://sqs.us-east-1.amazonaws.com/025631894481/aws-talk";
ReceiveMessageRequest request = new ReceiveMessageRequest(queueUrl);
request.MaxNumberOfMessages = 1;
ReceiveMessageResponse response = client.ReceiveMessage(request);
foreach (Message message in response.Messages)
{
// Do something with the message
client.DeleteMessage(queueUrl, message.ReceiptHandle);
}
36. SQS – Important Notes
Messages are not guaranteed to be delivered in order
In rare circumstances, messages can be delivered more than once
Dead letter queues can be created, allowing failed items to be
automatically moved after some number of failures
37. SNS (Simple Notification Service)
Topic ConsumersPublishers
Publishers send
messages to the topic
Consumers receive all
messages sent to the topic
38. SNS (Simple Notification Service)
Topic ConsumersPublishers
Publishers send
messages to the topic
All consumers receive all
messages sent to the topic
SQS Queue
39. SNS (Simple Notification Service)
Messages are not requested, they are pushed to subscribers
Subscribers are just endpoints
Endpoints can be: HTTP, HTTPS, Email, Email-JSON, SMS, SQS
41. S3 (Simple Storage Service)
Like a simple key-value store
Great for storing files
Store up to 5TB per object
Extremely scalable and durable
Highly available
42. Glacier
Similar to S3
Meant for archival – long term storage is durable and cheap
From the Glacier website:
“Glacier is designed with the expectation that retrievals are infrequent and unusual, and data
will be stored for extended periods of time. You can retrieve up to 5% of your average monthly
storage (pro-rated daily) for free each month. If you choose to retrieve more than this amount of
data in a month, you are charged a retrieval fee starting at $0.01 per gigabyte.”
Source: http://aws.amazon.com/glacier/pricing/
45. SimpleDB
Writing data
AmazonSimpleDBClient client = new AmazonSimpleDBClient(credentials,
RegionEndpoint.USEast1);
CreateDomainRequest request = new CreateDomainRequest("aws-talk");
CreateDomainResponse response = client.CreateDomain(request);
PutAttributesRequest putData = new PutAttributesRequest("aws-talk", "products/" +
Guid.NewGuid().ToString(),
new List<ReplaceableAttribute>()
{
new ReplaceableAttribute("Name", "Couch", true),
new ReplaceableAttribute("Price", "20", true)
});
client.PutAttributes(putData);
46. SimpleDB
Reading data
AmazonSimpleDBClient client = new AmazonSimpleDBClient(credentials,RegionEndpoint.USEast1);
// attribute names are case sensitive
// comparisons are lexicographical. no numeric comparisons exist
SelectRequest request = new SelectRequest(
"select * from `aws-talk` WHERE `Price` > '01'");
SelectResponse response = client.Select(request);
foreach (Item item in response.Items)
{
Console.WriteLine("Item {0} has attributes: {1}",
item.Name, String.Join(" ; ", item.Attributes.Select(a => string.Format("{0}={1}",
a.Name, a.Value))));
}
47. Pricing
Estimating it can be difficult
“Fixed” costs such as instance-hours or
gigabyte-months aren’t too bad
Requests are counted in “Cost per million”
And then factor in bandwidth, too.
Usually ends up being really cheap!
56. After creating a new account
• Go to “Security Credential”
• Create a user
• Make note of the Access Key ID and Secret Access Key
• Create a group to put that user into. I gave it power user
permissions
• Create the Security Group
• Create the Key Pair
• Launch the instance to create the AMI from
• Create the AMI
• Copy the AMI to all other regions
• Begin launching instances from that AMI
60. EC2
• Code: Launch a VM, get a list of VMs, kill a VM.
• Mention AMIs, Security Groups & Key Pairs
• Updating applications that are currently running
• Demo: Launch some VMs all around the world using an
existing AMI that I’ve deployed my “worker” to once.
• Workers run selfhost WebAPI so I can query their status
• Workers can auto-update(?) or can be told to update
• Instrumentation allows me to list VMs, update, kill, and see
other health/status points
61. EC2
• Before creating an instance, there are a few important things
• AMI = Amazon Machine Image.
• Launch an instance based off a public AMI first, and then
customize it as needed by installing your services. Then
you can save the AMI into that region and copy it into all
other regions as needed.
• Security Group – Like a set of Firewall rules
• VPC = Virtual Private Cloud. A private network for your
instances. (Only within a region???)
62. SQS
• Need a way to feed data to the workers, to give it work to do
• Queues are often used at application boundaries (seams)
• Common queueing patterns slide
• Talk about AWS implementation of those patterns
63. Data
• S3 – Basically just online file storage
• DynamoDB – Unstructured?
• Any SQL-like structured DBs?
64. SNS
• If there is time let’s talk about notifications
• SNS can do some cool things for us
The icons use FontAwesome. If they appear to be missing, try installing the font from here: http://fortawesome.github.io/Font-Awesome/
This talk covers EC2, which I consider to be Amazon’s most “famous” offering – an IaaS (Infrastructure as a Service) offering and how I was able to use it to solve a problem. It also covers SQS (queueing) and SNS (notifications) as well as a few data storage offerings. I will talk not only about what these things are but also how to manage them programmatically. The code I show will be in C# using the .NET SDK, which isn’t much more than a thin wrapper over the AWS REST API. So regardless of what your language of choice is, once you see how the API calls are named it will make sense in any language.
A little about me… serial entrepreneur. I’ve been involved in a lot of businesses and a lot of this talk is my story. Along the way I have learned a lot of things, and that’s what I want to share. The reason I got started is interesting..
Years ago I was working on a project where we had to grab data from a few data sources and aggregate it into one place. Like any other developer would, we created a Data Acquisition Application and got to it. It was simple and effective.
Overtime more and more data sources were added. But the application was well architected and handled them without issue.
But after some time we started connecting to data sources that were farther away.
You’re probably wondering at this point “So? What does that matter?” And it doesn’t until you put things into context (map shows up)
The actually had expanded dramatically since we started using it and we were now acquiring data from all over the world. This caused problems though because internet connections aren’t always great and international links sometimes go down, or connectivity outside of some countries/regions isn’t as quick as we’d like.
The first problem we’d run into is increased latency which meant we had to work around that when transferring data.
Some connections were not just slow but also intermittent.
And with a few of the worst ones we’d see long periods of time where no connection was possible.
However at the time that we were dealing with these problems Amazon had just recently launched EC2 in some of its data centers. This map is more recent than what was available then and represents the current infrastructure. As of October 2015, there is an additional European data center in Frankfurt, Germany which is not represented on this map.
While doing some testing with instances in data centers across the globe we noticed that a lot of our connection problems seem to be greatly reduced or even completely mitigated by connecting from a data center closer to the data source. So we began work on expanding the application to instances in each data center and assigning each data source to the closest data center.
And then a secondary benefit gained from this is that because we were sending our data to instances back in the states, that data was being transmitted through Amazon’s network. And believe me, Amazon is very committed to keeping the connection between data centers as quick as possible and practically without downtime.
To make this happen we used Amazon’s “EC2” offering which is basically infrastructure as a service. Meaning that when you start up an instance, you get this:
A remote desktop. Amazon maintains the infrastructure, handles the machine side of things, and provides you with an instance that is of a certain “size” depending on what you want.
There are a lot of terms that you will hear when dealing with EC2 instances, so here is a diagram to explain what some of those things mean in the context of EC2.
Go into the AWS control panel. Create a Security Group. Create a Key Pair. Create the Instance. RDP into the pre-created Instance (like Martha Stewart, pull the cookies out of the oven). Transition point: Talk about how to make the transition into managing these things with code. To do that I will need to go into IAM. Create a User. Create a Group. Add a user to the Group.
This very simple code can be powerful. I’ve created a dashboard where I can see my instances across the globe.
The way we set up the instances was to create an AMI with a windows service that can receive communications from the control panel. And then be updated from it as well by deploying a zip file to S3 and having the service update itself to the new version. So now.. wait for it.. there we go..
We have instances that can be updated to run any code we throw at it within minutes.