1

I need to schedule a .bat file which will install AWS CLI on windows and then upload files daily form a local directory to AWS S3.

My script looks like -

:: AWS CLI MSI installer for Windows (64-bit): https://s3.amazonaws.com/aws-cli/AWSCLI64.msi
aws --version

:: Create S3 bucket (not public), set bucket name and region (different than your EC2 region for better disaster recovery plan)
:: You can access your S3 bucket via CLI simply using s3://bucket-name
aws configure set AWS_ACCESS_KEY_ID {access_key_here}
aws configure set AWS_SECRET_ACCESS_KEY {secret_key_here}
aws s3 cp local_directory/* s3://{bucket_name_here}/

echo "complete"

I don't understand how the AWSCLI64.msi will be downloaded and installed through this script? How to do that ?

Seeker90
  • 785
  • 4
  • 17
  • 37

2 Answers2

0

Yes, you can do all the processes through Batch or Powershell (I prefer this more)

@echo off
:: AWS CLI MSI installation
SET "FILENAME=%~dp0\AWSCLI64.msi"
bitsadmin.exe /transfer "JobName" https://s3.amazonaws.com/aws-cli/AWSCLI64.msi "%FILENAME%"
msiexec /i "%FILENAME%" /qn /norestart

:: AWS CLI configuration
set userprofile=C:\Users\%username%
aws configure set AWS_ACCESS_KEY_ID <IAM_KEY>
aws configure set AWS_SECRET_ACCESS_KEY <IAM_SECRET>
aws configure set default.region <REGION>

:: S3 Bucket backup
aws s3 cp local_directory/* s3://{bucket_name_here}/
echo "complete"
Binh Nguyen
  • 1,891
  • 10
  • 17
0

Here is the solution for you.Run the commands on powershell.

Set-AWSCredentials –AccessKey key-name –SecretKey key-name Set-DefaultAWSRegion -Region us-east-2 Get-SSMDocumentList Get-SSMDocumentList Get-SSMDocumentDescription -Name "AWS-RunPowerShellScript" Get-SSMDocumentDescription -Name "AWS-RunPowerShellScript" | Select -ExpandProperty Parameters $runPSCommand = Send-SSMCommand -InstanceIds @("instance-ID-1", "instance-ID-2") -DocumentName "AWS-RunPowerShellScript" -Comment "Demo AWS-RunPowerShellScript with two instances" -Parameter @{'commands'=@('dir C:\Users', 'dir C:\')} Get-SSMCommand -CommandId $runPSCommand.CommandId Get-SSMCommandInvocation -CommandId $runPSCommand.CommandId Get-SSMCommandInvocation -CommandId $runPSCommand.CommandId -Details $true -InstanceId instance-ID | Select -ExpandProperty CommandPlugins

Get-SSMDocumentDescription -Name "AWS-InstallApplication" Get-SSMDocumentDescription -Name "AWS-InstallApplication" | Select -ExpandProperty Parameters $installAppCommand = Send-SSMCommand -InstanceId instance-ID -DocumentName "AWS-InstallApplication" -Parameter @{'source'='https://www.python.org/ftp/python/2.7.9/python-2.7.9.msi'; 'parameters'='/norestart /quiet /log c:\pythoninstall.txt'} Get-SSMCommandInvocation -CommandId $installAppCommand.CommandId -Details $true Get-SSMCommandInvocation -CommandId $installAppCommand.CommandId -Details $true -InstanceId instance-ID | Select -ExpandProperty CommandPlugins $installPSCommand = Send-SSMCommand -InstanceId instance-ID -DocumentName "AWS-InstallPowerShellModule" -Parameter @{'source'='https://gallery.technet.microsoft.com/EZOut-33ae0fb7/file/110351/1/EZOut.zip';'commands'=@('Add-WindowsFeature -name XPS-Viewer -restart')} -OutputS3BucketName demo-ssm-output-bucket Get-SSMCommandInvocation -CommandId $installPSCommand.CommandId -Details $true

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 12 '23 at 10:08