Automate AWS VPC Setup with AWS PowerShell and CSV

By | August 15, 2018

Automate AWS VPC Setup with AWS PowerShell and CSV

This post is about how to automate the creation of the Amazon Virtual Private Cloud Network for use with Amazon EC2 Instances. We can accomplish this task by filling out a .csv file and running the accompanying script. This script accomplishes the following based on the information provided in the .csv file for each row of the file.

  • Creates and Names a VPC
  • Creates and Names a Subnet
  • Creates and Names a Route Table
  • Associates a Subnet to the Route Table
  • Creates and Names a Internet Gateway
  • Associates The Internet Gateway with the VCP
  • Creates a Static Route to the Internet Gateway
  • Enables DNS Support
  • Builds a Security Group and Associates it with the VPC
  • Adds a Inbound Firewall Rule for the security group based on the information provided in the .csv file.

The goal of the script is to accomplish automation of the wizard based build process within the AWS console, while allowing the .csv file to be used for pre-install documentation for customers wanting to setup a new AWS VPC.  First lets examine our .csv file, which can be downloaded from the zip file below that contains both our script and the .csv file.

CSV File for VPC Automation Script


The file above shows that we are creating two VPCs with CIDR blocks of and Within these two VPCs, we have a single subnet range for each VPC, the region we want to create the VPC in, and Port/IP information for the security groups in each VPC. We also provide names for all of the components within the VPC.  Now let’s take a look at the actual script below and variables that will need to be edited.

User Required Modifications for VPC Automation Script

To login to AWS with PowerShell, the script will need the highlighted lines edited with the appropriate access key and secret key for your AWS environment and pointed to the appropriate location on your system where the .csv file is stored. The full script can be seen below.

AWS Script File

AWS VPC Script Running Output

The screenshots below shows the output of the script when run.

AWS VPC and Security Group Information from the AWS Console

The screenshots below shows the VPC components that were created from the script within the AWS console.


So as we can see, this is just one example of how we can use PowerShell to automate AWS tasks from a .csv file. I hope you all found this post useful and as always, thanks for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *