Created
November 23, 2019 22:39
-
-
Save libert-xyz/70c701d92dc04bd42dfc848afe21bbc9 to your computer and use it in GitHub Desktop.
Launch 100 EC2 + EIP and install vyprVPN
This file contains hidden or 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
| import logging | |
| import boto3 | |
| from botocore.exceptions import ClientError | |
| import time | |
| AMI='ami-0f93b5fd8f220e428' | |
| SUBNET='subnet-8f5e56e7' | |
| SG=['sg-0d5d78dc3b411252b'] | |
| REGION='us-east-2' | |
| KEY='VyprVPN-us-east-2' | |
| NAME='VyprVPN-us-east-2-NOV-' | |
| user_data = '''#cloud-config | |
| runcmd: | |
| - set -e | |
| - export DEBIAN_FRONTEND=noninteractive | |
| - for x in 1 2 3 4 5; do /usr/bin/curl -m 10 -o /bin/install-vyprvpn-server.sh "https://www.goldenfrog.com/downloads/vyprvpn/server/install-1.1.0.1.sh" && break; echo "Failed downloading install script"; sleep 1; done | |
| - test -f /bin/install-vyprvpn-server.sh | |
| - /bin/echo "7ebe8a828a385c9b39cced37463b9b3341653d64902f476b905198599b184314 /bin/install-vyprvpn-server.sh" | /usr/bin/sha256sum -c - | |
| - /bin/chmod 755 /bin/install-vyprvpn-server.sh | |
| - /bin/install-vyprvpn-server.sh | |
| - /bin/rm -f /bin/install-vyprvpn-server.sh | |
| - /bin/touch /tmp/vyprvpn-server-installed | |
| - /bin/echo Installation complete | |
| power_state: | |
| mode: reboot | |
| message: VyprVPN Server Installation Complete | |
| condition: /usr/bin/test -f /tmp/vyprvpn-server-installed''' | |
| f= open("us-east-2.txt","w+") | |
| ec2 = boto3.setup_default_session(region_name='us-east-2') | |
| ec2 = boto3.resource('ec2') | |
| eip = boto3.setup_default_session(region_name='us-east-2') | |
| eip = boto3.client('ec2') | |
| for i in range(1, 26): | |
| try: | |
| #EC2 | |
| instance_id = ec2.create_instances(ImageId=AMI, MinCount=1, MaxCount=1, KeyName=KEY, | |
| SecurityGroupIds=SG, UserData=user_data, InstanceType='t2.micro', SubnetId=SUBNET, | |
| TagSpecifications=[ | |
| { | |
| 'ResourceType': 'instance', | |
| 'Tags': [ | |
| { | |
| 'Key': 'Name', | |
| 'Value': NAME + str(i) | |
| }]}]) | |
| #print ('Instance ' + instance_id[0].instance_id + ' launched,' + ' wait until running....') | |
| time.sleep(50) | |
| # #EIP | |
| allocation = eip.allocate_address(Domain='vpc') | |
| response = eip.associate_address(AllocationId=allocation['AllocationId'], | |
| InstanceId=instance_id[0].instance_id) | |
| f.write(allocation['PublicIp'] + '\r\n') | |
| print (str(i) +'. ' + instance_id[0].instance_id + ' - ' + allocation['PublicIp']) | |
| except ClientError as e: | |
| f.close() | |
| print(e) | |
| f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment