Automate EC2 Instance Creation With Python's Boto3 Library

Automate EC2 Instance Creation With Python's Boto3 Library

Table of contents

No heading

No headings in the article.

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.

And after that, when you run the Function osLaunch(), it will create a new ec2 instance, and as many times you 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