Native AWS Windows Server SQL Backup to S3

Hi Guys,

Can anybody help to fix this issue I have followed below script to take SQL backup from AWS Windows server to move to S3 bucket. Partially PS script is working fine until taking backup and store in server but facing error to move to S3.



$server = ‘.’
$database = ‘MyDatabase’
$s3Bucket = ‘s3-sql-backups’
$backupPath = 'C:\SqlBackup'
$region = ‘eu-west-1’

accessKey and secretKey can be removed if running on an EC2 instance and using IAM roles for security

$accessKey = ‘USER-ACCESS-KEY’
$secretKey = ‘USER-SECRET-KEY’

$timestamp = get-date -format yyyyMMddHHmmss
$fileName = “$database-$timestamp.bak”
$filePath = Join-Path $backupPath $fileName

Backup-SqlDatabase -ServerInstance $server -Database $database -BackupFile $filePath

AccessKey and SecretKey can be removed if running on an EC2 instance and using IAM roles for security

Write-S3Object -BucketName $s3Bucket -File $filePath -Key $fileName -Region $region -AccessKey $accessKey -SecretKey $secretKey
Remove-Item $backupPath$database*.bak


Error Description:

Write-S3Object : Name resolution failure attempting to reach service in region us-east-1 (as supplied to the -Region parameter or
from configured shell default).
The remote server returned an error: (403) Forbidden…
Possible causes:

  • The region may be incorrectly specified (did you specify an availability zone?).
  • The service may not be available in the region.
  • No network connectivity.
    See AWS service endpoints - AWS General Reference for the latest service availability across the AWS regions.
    At C:\Users\xxxx\Desktop\Backup-Script-2.ps1:19 char:1
  • Write-S3Object -BucketName $s3Bucket -File $filePath -Key $fileName - …
  • CategoryInfo : NotSpecified: (:slight_smile: [Write-S3Object], Exception
  • FullyQualifiedErrorId : System.Exception,Amazon.PowerShell.Cmdlets.S3.WriteS3ObjectCmdlet




have you checked whatever mentioned in the error ?

Hi Prasoon,

I believe found the root cause of the error. Actually Windows EC2 instance is in domain and in Pvt. IP so it wont dont have internet to connect S3 bucket thats we got this error. I can tried in NON-Domain server and we can copy data to S3 bucket.

Now I need also how we can Zip 4GB .bak file and send mail notification once successful backup has done along with above script.