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:
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: