Automating The Creation Of EC2 Instances With Boto3

Piyush KabraPiyush Kabra
2 min read

First of all, you have to install AWS CLI from here

Open the Command prompt and type python there, after that, this \>>> will open which means you are now in Python Terminal.

Then Create a variable named myec2 or anything else you want to create, and inside that write the command shown.

After this, define a function osLaunch(), and enter the details in that.

And after that when you will run the Function osLaunch(), then it will create a new ec2 instance, and as many times you will run this command, a new ec2 instance will be created.

See the instance ID in the Terminal and in the AWS Portal

Track Instances with a list

myosList = [] # Declaring an empty list
myos = osLaunch() # Launching an instance
print(myos) # Checking the returned value
myosList.append(myos[0].id) # Storing the instance ID

However, for this method to run without giving your AWS credentials, you have to set or configure your AWS key and Regions in the local system using the AWS configure command.

To Take the Credentials go to your AWS account & do the following

Select Security Credentials from your account name

Then go here and click on the Create Access Key

Accept & Click on Create Access Key

Copy the Access Key & Secret Access Key From here and paste them to your AWS configure command & select write region name code.

To Check that aws is configured run the command, AWS configure list


0
Subscribe to my newsletter

Read articles from Piyush Kabra directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Piyush Kabra
Piyush Kabra