Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hybrid Cloud for Developers

You're reading from   Hybrid Cloud for Developers Develop and deploy cost-effective applications on the AWS and OpenStack platforms with ease

Arrow left icon
Product type Paperback
Published in Apr 2018
Publisher Packt
ISBN-13 9781788830874
Length 280 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Manoj Hirway Manoj Hirway
Author Profile Icon Manoj Hirway
Manoj Hirway
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Introducing Hybrid Clouds FREE CHAPTER 2. Exploring AWS Cloud 3. Exploring OpenStack Private Cloud 4. Developing AWS Cloud Applications 5. Developing OpenStack Applications 6. Cloud Migration 7. Hybrid Cloud Best Practices 8. Monitoring and Troubleshooting Hybrid Cloud 9. Hybrid Cloud Security 10. Other Books You May Enjoy

Developing Amazon EC2 applications – Unix


Let's start by launching a new EC2 instance using the boto3 library.

Launching an EC2 instance in Python

Launching an EC2 instance using the Python boto3 library hardly takes a few lines of code. You only have to create an instance of the ec2 type using the resource() function of the boto3 library and invoke its create_instances() function. This function takes parameters specific to the instance such as Amazon Machine Image identified, key name, instance type, and so on.

The following simple program will launch the AWS EC2 instance:

import boto3

ec2 = boto3.resource('ec2')

instance = ec2.create_instances(
    ImageId='ami-bf4193c7',
    MinCount=1,
    MaxCount=1,
    KeyName="access",
    InstanceType='t1.micro')
print instance[0].id

Note that the Amazon Machine Image that you specify in the program should be present in the same region that was configured using the aws configure CLI in the beginning of this chapter.

Listing EC2 instances in Python...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime