AWS User Data Script | Auto Provision a Windows EC2 Instance
How to Script (Auto Provision) an AWS Windows EC2 Instance
To auto provision an AWS Windows instance with a script that runs when the instance comes up – is a common (but poorly documented requirement). Scroll down for links to other net resources on this subject.
Intro | AWS User Data Script that Auto Provisions a Windows Server
We are going to
- use the Amazon Cloud Windows EC2 Instances
- auto provision SQL Server on Windows 2016
- use the Ruby AWS SDK to create the Windows instance
- use basic Windows Command Prompt (.bat) statements
- use an S3 bucket to hold the database backup
We employ one
PowerShell statement within the user data script to download the database backup file with plain old http. The powershell command is simple & succinct – that’s why we use it.
Use Case | Provisioning a Windows AWS SQL Server EC2 Instance
We don’t want human hands touching the Windows instance. And neither do you (as you are reading this).
Look, but don’t touch.
The “Hello Windows World” is too simplistic to be of value. Even if your use case is different, this one is complete enough to cover most aspects of auto provisioning a Windows instance.
The User Data Script Does 3 Things
We want our aws user data script to do 3 things.
- use sqlcmd to create a database user with sufficient permissions
- use a presigned url to download the database (file) from an S3 bucket
- unravel the file into a ready SQL Server database service
Why Use a Presigned Url? – Simplicity! We don’t want a publicly readable S3 database file. We don’t want to add tedious IAM policies, roles and AWS credentials to neither the Windows instance nor the script.
Furthermore the pre-signed url won’t work after 15 minutes – you can decrease or increase this up to one week.