Skip to content

Commit d35b4c2

Browse files
authored
Merge pull request #50 from DiptoChakrabarty/master
ec2-launcher script
2 parents 6b6d407 + 446cdb9 commit d35b4c2

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

EC2-launcher/.env

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
ACCESS_KEY=""
2+
SECRET_KEY=""
3+
AMI=""
4+
REGION=""
5+
ZONE=""
6+
TYPE=""
7+
SUBNET=""

EC2-launcher/ec2.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import boto3,os
2+
from dotenv import load_dotenv
3+
load_dotenv()
4+
5+
#Load env variables
6+
access_key= os.getenv("ACCESS_KEY")
7+
secret_key= os.getenv("SECRET_KEY")
8+
ami= os.getenv("AMI")
9+
region= os.getenv("REGION")
10+
zone= os.getenv("ZONE")
11+
type= os.getenv("TYPE")
12+
subnet = os.getenv("SUBNET")
13+
14+
client = boto3.client(service_name='ec2', region_name=region, aws_access_key_id= access_key,aws_secret_access_key= secret_key)
15+
16+
# Create ec2 resource
17+
ec2 = boto3.resource('ec2', region_name=region, aws_access_key_id= access_key,aws_secret_access_key= secret_key)
18+
# create an instance
19+
instance = ec2.create_instances(
20+
ImageId = ami,
21+
MinCount = 1,
22+
MaxCount = 1,
23+
InstanceType = type,
24+
KeyName = key_name,
25+
SubnetId = subnet)
26+
27+
instance.wait_until_running()
28+
print("Instance Up and Running")

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,4 @@ This is a collection of short Python scripts to solve and automate tasks and sim
4747
27 | [**AutoCursorHover**](https://github.com/fnplus/Python-scripts-collection/tree/master/AutoCursorHover) | Python script for continues hover of the cursor to keep you online all the time | pyautogui package
4848
28 | [**ITBookDownloader**](https://github.com/disha2sinha/Python-scripts-collection/tree/master/ITBookDownLoader) | Python script for searching through and downloading PDF version of books from sites like [link](http://www.allitebooks.in/) multiple times | Selenium
4949
29 | [**CoV-Updates-Emailer**](https://github.com/evi1haxor/CoVup.git) | Arrangements have been made so that the script would automatically trigger itself off every morning and send an email to all the subscribers regarding the latest CoV pandemic stats about their district (like active cases, confirmed cases, recovered cases and deceased cases). Read more about it in the README. | requests, json, smtplib, email, string
50+
30 | [**EC2-Instance-Launcher**](https://github.com/DiptoChakrabarty/Useful-Python-scripts-collection/blob/master/EC2-launcher/ec2.py) | Python script to automatically launch ec2 instances in AWS | boto3 , botocore , python-dotenv , environmental variables

0 commit comments

Comments
 (0)