forked from rchidana/Python_Boto3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateec2.py
More file actions
17 lines (17 loc) · 844 Bytes
/
Createec2.py
File metadata and controls
17 lines (17 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import boto3
ec2 = boto3.resource('ec2')
tags = [
{'Key':'Name','Value': 'Boto3-EC2'},
{'Key': 'Department', 'Value': 'Web-Dep'},
]
tag_specification = [{'ResourceType': 'instance', 'Tags': tags},]
instances = ec2.create_instances(MinCount=1, MaxCount=1, ImageId='ami-a4dc46db', InstanceType='t2.micro', SecurityGroups=['ACCENTURE_SEC_GROUP'], KeyName='ACCENTURE_KEYS',TagSpecifications=tag_specification) # create one instance with a t2.micro instance-type
for instance in instances:
print("waiting for the instance to be running state")
instance.wait_until_running()
instance.reload()
print("Instance id ", instance.id)
print("Instance state ", instance.state['Name'])
print("Instance public DNS", instance.public_dns_name)
print("Tagging the instance")
ec2.Tag(instance.id, 'Name','Boto-Tag')