In this article, we will learn how to deploy a MSSQL database using Amazon Web Services (AWS) RDS and PowerShell. We will use the following steps:
- Create an Amazon Web Services (AWS) RDS instance.
- Deploy the MSSQL database on the RDS instance.
- Configure the database settings.
Like many other AWS services, you can manage RDS databases in a few different ways, such as through the AWS Management Console, AWS CLI tool, any number of SDKs, or with PowerShell. The choice of which method is best is yours. (If you’re on a team with PowerShell gurus or already have some AWS automation scripts written in PowerShell, a PowerShell script can get the job done well though.)
In this article, you’re going to learn how to use PowerShell and the AWS PowerShell module to deploy an AWS RDS instance in no time!
Prerequisites
To follow the steps in this article, you must first ensure that you’ve met a few assumed prerequisites. I expect that you already met these requirements:
Created an AWS account Are using PowerShell Core (I’m using PowerShell 6. 2. 0. ) Have downloaded and installed the AWS. Tools. RDS PowerShell module (I’m using v3. 3. 590. ) Authenticated to your AWS account the root user or an IAM user with rights to create an RDS instance
Once you’ve confirmed that you meet all of these requirements, let’s get started!
Deciding What Kind of RDS Instance to Deploy
Before you begin coding, you must figure out what kind of RDS instance to create. To deploy an RDS instance with PowerShell, you are required to know a few keys attributes:
Name of the instance Engine (SQL Server, MariaDB, MySql, and so on) Instance class that assigns what kind of resources the SQL Server database will be run on Master username and password How big the database should be in gigabytes
This article explains how to find each of these attributes to create an RDS instance with PowerShell.
Finding Available Engine Versions
While you are creating an MSSQL RDS instance using this article, it’s essential to know you have other options. Run the Get-RDSDBEngineVersion command and group by engine name to see a list of available database types.
Because you have deployed an MSSQL RDS instance, research that version bit more to see all of the available versions.
Finding the Instance Class
Creating the RDS Instance
By now, you should have the name of the RDS instance you’d like to create, the engine, instance class, and the username/password to assign to it. It’s now time to create it.
To create a new RDS instance with PowerShell, use the New-RDSDBInstance cmdlet. This single cmdlet enables you to pass all of the parameters you need to create an instance.
Below, you can see an example of using the New-RDSDBInstance cmdlet to create an instance with:
A name of CloudSavvy The MSSQL database engine (SQL Express latest version) A db. t2. micro instance class An sa user with a password of password 20 GB in size An interface that enables connections over the Internet
In the example, the output from the command is getting assigned to a variable called $instance.
When the New-RDSDBInstance command runs, it returns control to the PowerShell console before the instance is created. To monitor the creation process, you can monitor the DBInstanceStatus property returned by Get-RDSDBInstance.
By using a little PowerShell magic with a while loop, you can create code that will wait for the instance to enter the available status before releasing control.
In the following example, PowerShell checks for the status of available every 30 seconds. As soon as the instance enters this state, it releases control.
Once PowerShell releases control, you can then check the AWS Management Console and confirm the RDS instance has been created. To do so, you can either navigate to the RDS service section or follow this link, but be sure to replace it with the region name with which you’re working:
Summary
By following a step-by-step process, you now know how to deploy an AWS RDS instance with PowerShell. And, by using the code discussed in this article, you are able to use this in larger automation scripts or create an instance via the PowerShell console as you wish.