Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettes committed Feb 24, 2016
0 parents commit a088f25
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.pem
.idea/
10 changes: 10 additions & 0 deletions ec2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env python
import boto3

ec2 = boto3.resource('ec2')

# launch an instance
instances = ec2.create_instances(ImageId='ami-11032472',
InstanceType='t2.micro',
MinCount=1,
MaxCount=1)
43 changes: 43 additions & 0 deletions ec2_extra.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python
import boto3
import botocore.exceptions

ec2 = boto3.resource('ec2')

# allow SSH access
try:
security_group = ec2.create_security_group(GroupName='ssh_access',
Description='pug talk')
security_group.authorize_ingress(IpProtocol='tcp',
CidrIp='0.0.0.0/0',
FromPort=22,
ToPort=22)
except botocore.exceptions.ClientError:
pass


# create SSH key
try:
key = ec2.create_key_pair(KeyName='cpug')
with open('cpug.pem', 'w') as file:
file.write(key.key_material)
except botocore.exceptions.ClientError:
pass


# launch an instance
instances = ec2.create_instances(ImageId='ami-11032472',
InstanceType='t2.micro',
MinCount=1,
MaxCount=1,
SecurityGroupIds=['ssh_access'], # <-- security group
KeyName='cpug') # <-- ssh key


print('launching')

instances[0].wait_until_running()

print('running')
print('might need to run: chmod 400 cpug.pem')
print('type: ssh -i cpug.pem ec2-user@' + ec2.Instance(instances[0].id).public_ip_address)

0 comments on commit a088f25

Please sign in to comment.