-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a088f25
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.pem | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |