Find knowledge base article(s) by searching for keywords in the title e.g. type linux in the search box below
Find knowledge base article(s) by browsing the subject categories of articles
Technology quick references, cheatsheets, user manuals etc.
Shop Online through ShopifyLite
Tutorials on various IT applications.
Search Title    (UL:0 |SS:f)

Services >> Cloud >> AWS >> SDK >> Python >> boto3 >> How to manage EC2

 

List instances

#!/bin/python
import boto3
ec2 = boto3.resource('ec2')
for instance in ec2.instances.all():
   print instance.id, instance.state

 

Create Instance

#!/bin/python
import boto3
ec2 = boto3.resource('ec2')
instance = ec2.create_instances(
    ImageId='ami-fdb8229e',
    MinCount=1,
    MaxCount=1,
    InstanceType='t2.micro',
    KeyName='yourkeyname',
    UserData='#!/bin/bash;yum install -y httpd24;echo bootstrapped > /var/tmp/bootstrap.log',
    TagSpecifications=[
        {
            'ResourceType': 'instance',
            'Tags': [
                {
                    'Key': 'Name',
                    'Value': 'Web server 5'
                },
            ]
        },
    ]
    )
print instance[0].id

 

References:

https://docs.aws.amazon.com/code-samples/latest/catalog/code-catalog-python.html

[ © 2008-2021 myfaqbase.com - A property of WPDC Consulting ]