Overview
This lab covers deploying and operating a Windows EC2 instance running SQL Server Express in a private subnet designed for internal-only database access. The document focuses on network design (VPC, route tables, NAT, VPC endpoints), secure administration via AWS Systems Manager (SSM), SQL Server silent installation and hardening, backup/restore (EBS snapshots and SQL backups to S3), monitoring, and production-ready operational practices.
Prerequisites
Learning objectives
Network & VPC design
Recommended subnet layout:
Route tables:
VPC Endpoints:
com.amazonaws.<region>.ssm, com.amazonaws.<region>.ec2messages, com.amazonaws.<region>.ssmmessages to allow SSM traffic without Internet.Security groups & NACLs
Security Group for SQL Server (db-sg):
Management Security Group (mgmt-sg):
Network ACLs: keep default permissive rules or implement stateless filters if required by policy; Security Groups are primary control.
IAM & instance profile
Create an IAM role for EC2 with the following managed policy to enable SSM:
AmazonSSMManagedInstanceCoreAdditional policies (add least privilege scope):
ec2:CreateSnapshot, ec2:DescribeVolumes, etc.Instance type, storage, and AMI choices
Windows & SQL Server installation (automation)
PowerShell (on instance) - silent install example for SQL Server Express:
# Download installer
$url = "https://download.microsoft.com/.../SQLEXPR_x64_ENU.exe"
Invoke-WebRequest -Uri $url -OutFile C:\Temp\sqlexpr.exe
# Create configuration file (simple example)
$config = @"
[OPTIONS]
ACTION=Install
FEATURES=SQLENGINE
INSTANCENAME=SQLEXPRESS
SECURITYMODE=SQL
SAPWD="P@ssw0rd"
SQLSVCACCOUNT="NT AUTHORITY\SYSTEM"
TCPENABLED=1
NPENABLED=0
"@
$config | Out-File C:\Temp\ConfigurationFile.ini -Encoding ascii
# Run silent installer
& C:\Temp\sqlexpr.exe /Q /ACTION=Install /IACCEPTSQLSERVERLICENSETERMS /ConfigurationFile=C:\Temp\ConfigurationFile.ini
Firewall & Windows Defender
Administration via SSM
aws ssm start-session --target i-0123456789abcdef0
Start-SSMSession -Target i-0123456789abcdef0 -DocumentName AWS-StartPortForwardingSession -Parameters @{"portNumber"=["3389"];"localPortNumber"=["13389"]}
Connectivity from Lambda or app
If using Lambda in the same VPC, ensure Lambda’s vpcConfig includes private subnet IDs and security group IDs that allow outbound to db-sg on 1433. Remember Lambda will create ENIs in the subnets which affects cold-start.
Testing connectivity:
Test-NetConnection -ComputerName 10.0.x.10 -Port 1433 (PowerShell)tcping/telnet for TCP checks.Backups and restore
Two layers of backups recommended:
Automate snapshots with AWS Data Lifecycle Manager (DLM) or Lambda triggered by CloudWatch Events.
Restore test: create volume from snapshot, attach to a recovery instance, mount and verify SQL files or restore .bak files to a new SQL Server instance.
Monitoring, logging, and patching
Hardening & security
Troubleshooting checklist
C:\Program Files\Microsoft SQL Server\MSSQL..\MSSQL\Log), verify TCP/IP enabled and SQL service running.Cleanup
References & further reading