<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SpaziDigitali &#187; aws</title>
	<atom:link href="http://spazidigitali.com/tag/aws/feed/" rel="self" type="application/rss+xml" />
	<link>http://spazidigitali.com</link>
	<description>Luca Mearelli's Blog</description>
	<lastBuildDate>Tue, 25 Jan 2011 17:14:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Controlling an EC2 instance with python</title>
		<link>http://spazidigitali.com/2009/03/17/controlling-an-ec2-instance-with-python/</link>
		<comments>http://spazidigitali.com/2009/03/17/controlling-an-ec2-instance-with-python/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 21:24:32 +0000</pubDate>
		<dc:creator>lm</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[boto]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[redis]]></category>

		<guid isPermaLink="false">http://spazidigitali.com/?p=140</guid>
		<description><![CDATA[One of the selling points of EC2 is that it enables elastic provisioning of computing infrastructure; this allows following novel usage patterns where a server is used only for the time required to do some work. The key to reach this flexibility is the API that gives developers the ability to startup a server, configure [...]]]></description>
			<content:encoded><![CDATA[<p>One of the selling points of EC2 is that it enables elastic provisioning of computing infrastructure; this allows following novel usage patterns where a server is used only for the time required to do some work.</p>
<p>The key to reach this flexibility is the API that gives developers the ability to startup a server, configure it, use it and shut it down. There are libraries for many programming languages but I like the way the boto python library makes it really simple do these things (and a lot more).</p>
<p>Here I&#8217;ll show how to use <a href="http://code.google.com/p/boto/">boto</a> to start a server instance then how to send a file to the instance and execute a command on the remote server, and finally I&#8217;ll show how to terminate the instance.<br />
<span id="more-140"></span><br />
To use the boto library you&#8217;ll need to install it locally (on your computer) and to use the EC2 api you&#8217;ll need to import them:</p>
<pre class="brush: python; title: ;">
from boto.ec2.connection import EC2Connection
</pre>
<p>As with  other AWS services you&#8217;ll need to pass the access key and the secret access key to the library (in this case when creating a connection). You can get the keys from the Amazon Web Services &#8220;Access Identifiers&#8221; page. It&#8217;s possible to just set two environment variables holding the keys or you can pass them in to the method calls, I&#8217;ll assume for this example that the keys are written inside the script and passed to the methods:</p>
<pre class="brush: python; title: ;">
AWS_ACCESS_KEY_ID = 'yourkey'
AWS_SECRET_ACCESS_KEY = 'yoursecret'

conn = EC2Connection(AWS_ACCESS_KEY_ID,
AWS_SECRET_ACCESS_KEY)
</pre>
<p>First step is to make the connection, Once the connection is created we can use the run_instance to start an instance of an EC2 server image. You can think of a server image as a pre-built virtual server that&#8217;s idle waiting to be run. There are public images we can choose from (I&#8217;ll use the base Linux Fedora for this example), but any user can customize a running instance and build a private image from that ready to be used.</p>
<pre class="brush: python; title: ;">
reservation = conn.run_instances('ami-5647a33f',
                               instance_type='m1.small',
                               key_name='mykey')

instance = reservation.instances[0]

while not instance.update() == 'running':
  time.sleep(5)
</pre>
<p>the run_instances can take various parameters but only the image is required. Here I&#8217;m passing in also the instance type (in this case the &#8220;Small&#8221; instance type) and a key to use. The key to be used should have been previously generated and/or uploaded to EC2 (e.g. using the AWS Management Console).</p>
<p>The run_instances methods returns a reservation object representing the instance(s) startup request. This also holds the list of instances that are going to be started (we may launch more than one instance in a single run_instances call), in this case (since we are launching just one) we take the first one.</p>
<p>Each instance object has an attribute status which returns its current status, to check for the current status we need to call the update method (which itself returns the current status). When the instance is running it is given a public IP and a public dns name, which we may use to connect.</p>
<p>EC2 has a very flexible shared firewall whose rules and permissions may be manipulated via the API, for instance to enable or disable  connecting via SSH. Different security groups may be defined, to partition our instances into different logical sets e.g. web servers versus backend databases, and each group can be assigned different permissions. All the instances are assigned the &#8216;default&#8217; security group if not otherwise specified.</p>
<p>With a call to the authorize_security_group method we can allow a specific connection for a given group. E.g. with the following call we  allow SSH to any instance in the default group from the specified IP.</p>
<pre class="brush: python; title: ;">
conn.authorize_security_group('default',
                ip_protocol='tcp',
                from_port='22',
                to_port='22',
                cidr_ip='%s/32' % our_ip)
</pre>
<p>with the following call we can revoke the SSH permission</p>
<pre class="brush: python; title: ;">
conn.revoke_security_group('default',
                ip_protocol='tcp',
                from_port='22',
                to_port='22',
                cidr_ip='%s/32' % our_ip)
</pre>
<p>Once the instance is running and the permissions are setup to allow connecting via ssh, we can connect to it and to run a script on the instance we may simply scp the script and then connect via ssh to run it.</p>
<p>When we are done with the work we can stop use the stop method of the instance object to shut it down:</p>
<pre class="brush: python; title: ;">
instance.stop()
</pre>
<p>For a simple, yet complete example here is a script that can be used to run the benchmarks for the <a href="http://code.google.com/p/redis/">redis key-value store</a> on EC2. In the archive, together with the python script there is a shell script which is copied to the server which downloads the redis code, compiles it and runs the benchmarks:</p>
<p><a href="http://spazidigitali.com/wp-content/uploads/2009/03/redis-bench-ec2.zip">redis-bench-ec2.zip</a></p>
<p>That&#8217;s all!</p>
<p><a href="http://spazidigitali.com/wp-content/uploads/2009/03/redis-bench-ec2.zip"><br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://spazidigitali.com/2009/03/17/controlling-an-ec2-instance-with-python/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cobol Cloud</title>
		<link>http://spazidigitali.com/2009/01/16/cobol-cloud/</link>
		<comments>http://spazidigitali.com/2009/01/16/cobol-cloud/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 20:07:18 +0000</pubDate>
		<dc:creator>lm</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[cloud]]></category>
		<category><![CDATA[ERP]]></category>

		<guid isPermaLink="false">http://spazidigitali.com/?p=129</guid>
		<description><![CDATA[Cloudification of IT services will be a growing trend in the coming months, one (big) step forward in this process is the announce today that Microfocus has released a virtualized mainframe environment which will let enterprises run CICS and IMS code in the cloud The real breakthrough is that this will enable a whole sector [...]]]></description>
			<content:encoded><![CDATA[<p><em>Cloudification </em>of IT services will be a growing trend in the coming months, one (big) step forward in this process is the announce today that <a href="http://aws.typepad.com/aws/2009/01/mainframes-in-the-cloud.html">Microfocus has released</a> a virtualized mainframe environment which will let enterprises run CICS and IMS code in the cloud</p>
<p>The real breakthrough is that this will enable a whole sector within our industry to transition to a modern architecture. There are a lot of ISVs which have invested heavily and have a great knowhow in mainframe technologies and those were facing tough times with clients lending towards web services and cloud systems to renew their IT (this is specially true for many small italian software houses working on ERP systems).</p>
<p>With this offering those ISVs will be able to transition current clients to cloud systems and perhaps they will be able to re-engineer and modernize their software one piece at a time as hopefully the Microfocus service will enable new ways to integrate mainframe software and internet services.</p>
]]></content:encoded>
			<wfw:commentRss>http://spazidigitali.com/2009/01/16/cobol-cloud/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backup to S3</title>
		<link>http://spazidigitali.com/2009/01/10/backup-to-s3/</link>
		<comments>http://spazidigitali.com/2009/01/10/backup-to-s3/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 09:26:55 +0000</pubDate>
		<dc:creator>lm</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[boto]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[s3]]></category>

		<guid isPermaLink="false">http://spazidigitali.com/?p=111</guid>
		<description><![CDATA[Here is a small script I&#8217;m using to backup files to S3. Actually it implements all the basic operations you need for S3 (bucket creation, listing, file upload and download). It&#8217;s rather trivial but I was able to keep it so simple, thanks to it&#8217;s use of the Boto python library to do all of [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a small script I&#8217;m using to backup files to S3. Actually it implements all the basic operations you need for S3 (bucket creation, listing, file upload and download).</p>
<p>It&#8217;s rather trivial but I was able to keep it so simple, thanks to it&#8217;s use of the <a href="http://code.google.com/p/boto/">Boto python library</a> to do all of the AWS heavywork. Anyhow I think it may be useful.</p>
<p>A few examples:</p>
<p><script src="http://gist.github.com/45427.js"></script></p>
<p>Here is the code:<br />
<span id="more-111"></span></p>
<p><script src="http://gist.github.com/45423.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://spazidigitali.com/2009/01/10/backup-to-s3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

