Home > Uncategorized > Accessing #AWS #CLI from #SQL Server Agent

Accessing #AWS #CLI from #SQL Server Agent


The AWS CLI allows you to interact with AWS from the command line, and an obvious use of the tool, is to upload your Database Backups to S3, to keep them safe.

Once you’ve configured AWS to run from the command line on your server, and tested it, then you try the exact same command from xp_cmdshell and it fails with “unable to locate credentials“.

What is happening here, is your remote desktop user, is probably “Adminstrator” but SQL server agent runs under the username MSSQLSERVER

You can verify the username used by SQL server agent by runing the command

xp_cmdshell ‘echo %username%’

The AWS CLI is looking for the configuration file under c:\users\MSSQLSERVER\.aws – but the configuration file is actually under c:\users\Adminstrator\.aws , so you need to copy the configuration file using xp_cmdshell as follows

  1. Using remote desktop, copy the configuration file to an accessible folder, like C:\temp
  2. xp_cmdshell ‘md C:\users\MSSQLSERVER\.aws’

    xp_cmdshell ‘copy c:\temp\credentials c:\users\MSSQLSERVER\.aws’


  3. And then test with
    xp_cmdshell ‘”C:\Program Files\Amazon\AWSCLI\bin\aws.exe” s3 ls’
Categories: Uncategorized
  1. February 6, 2020 at 2:40 pm

    xp_cmdshell ‘echo %userprofile%’ works better!


  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: