Using Amazon Web Services (AWS), we can use their Relational Database Service (RDS) to deploy an MS-SQL database quickly and easily using PowerShell. Let's jump in and see how!

Before we get too far, make sure you have the AWSPowerShell module installed by running Install-Module -Name AWSPowerShell. Also make sure you have already authenticated to your AWS account.

The first task we'll need to do is figure out which "engine" we need to use. An "engine" in RDS terms is simply the server type, so think of SQL Server, Postgres, etc. The way to get all the available engines is by using the Get-RDSDBEngineVersion command. Since this command returns lots of output, and right now, I'm only interested in the engine names, I can group the output by Engine.

Viewing engine types

Viewing engine types

For our purposes, I want just to use the SQL Server Express Engine since it's free! We're not going to be doing anything crazy at this point. If you look down the list of engines returned from the command above, you'll notice sqlserver-ee, -ex, -se, and -web. These designate Enterprise, SQL Server Express, Standard Edition, and Web Edition; -ex is SQL Server Express Edition, so this will be our engine.

Once we figure out the engine to use, we'll then need to figure out the engine version. To do this, we can use the Get-RDSDBEngineVersion command again. This time, we're going to use the Engine parameter and pass the engine name sqlserver-ex. This returns a list of all the engine versions we can use.

By default, the new New-RDSDBInstance command will create a database using the latest version, but if you need an older version, you can choose from the list returned. At the time of this writing, this version is 14.00.3035.2.v1.

Next, we'll need to know the instance class to create. Unfortunately, this list isn't available via PowerShell, but you can refer to the RDS instance types page at AWS for the complete list. For our scenario, I'll be using db.t2.micro.

Once we've got all of these parameters together, we're now ready to create the database instance using the New-RDSDBInstance command. To do this, we pass all the parameters we just figured out along with the username, password, and size of the database to create. You can see below I'm also optionally making the instance accessible over the internet, but this isn't mandatory.

Once this command finishes, you'll see a lot of output. One of the properties is the DBInstanceStatus property. At this time, it's in a creating state.

Instance in a creating state

Instance in a creating state

Before using the instance, we're going to need to wait for it to finish. To do this, we can use the Get-RDSDBInstance command using the DBInstanceIdentifier parameter and inspecting the DBInstanceStatus property. When running this, you'll find this returns a string of creating if you're following along.

I'd rather not run this command over and over waiting forever, so I'll just create a PowerShell while loop that will run continuously until the state shows up as available.

When the above code runs, it will halt the console or script (if you're running this in a script) until the instance status goes to available.

After this while loops returns control, you've deployed your MS-SQL RDS instance!

Join the 4sysops PowerShell group!

Your question was not answered? Ask in the forum!

0
Share
0 Comments

Leave a reply

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

*

© 4sysops 2006 - 2020

CONTACT US

Please ask IT administration questions in the forums. Any other messages are welcome.

Sending

Log in with your credentials

or    

Forgot your details?

Create Account