[python]Trying out AWS SDK

I got myself a free basic account to do some hands on try outs. It is not necessary to use the AWS SDK to invoke the API. This try out is to write a simple static script to create a new VPC and subnet from this new vpc.
The SDK is known as boto3, you can use pip to download the sdk. For this script to run I created an api account with the below three permissions:
Screenshot 2018-10-19 at 10.08.50 PM.png
Here’s the code:

import boto3


# For a list of region names refer https://docs.aws.amazon.com/general/latest/gr/rande.html
boto3.setup_default_session(
    aws_access_key_id='key is obfuscated',
    aws_secret_access_key='key is obfuscated',
    region_name='ap-southeast-1'
)

ec2 = boto3.resource('ec2')
try:
    vpc = ec2.create_vpc(CidrBlock='192.168.1.0/24')
    vpc.create_subnet(CidrBlock='192.168.1.0/28')
    ec2.create_internet_gateway()
except BaseException as e:
    print(e)

Here’s the result:
Screenshot 2018-10-19 at 10.12.53 PM
Screenshot 2018-10-19 at 10.13.46 PM

Advertisements
This entry was posted in Python, Scripting and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s