[英]how to install awscli.msi and upload files to s3 using .bat script?
我需要安排一個 .bat 文件,它將在 windows 上安裝 AWS CLI,然后每天將文件從本地目錄上傳到 AWS S3。
我的腳本看起來像 -
:: 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"
我不明白 AWSCLI64.msi 將如何通過此腳本下載和安裝? 怎么做?
是的,您可以通過Batch或Powershell完成所有流程(我更喜歡這個)
@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"
這是適合您的解決方案。在 powershell 上運行命令。
Set-AWSCredentials –AccessKey 鍵名 –SecretKey 鍵名 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
-Name "AWS-RunPowerShellScript" | Select -ExpandProperty Parameters $runPSCommand = Send-SSMCommand
-InstanceIds @("instance-ID-1", "instance-ID-2") -DocumentName "AWS-RunPowerShellScript"
"Demo AWS-RunPowerShellScript with two instances" -Parameter @{'commands'=@('dir C:\Users', 'dir C:\')} Get-SSMCommand
-CommandId $runPSCommand.CommandId Get -CommandId $runPSCommand.CommandId Get-SSMCommandInvocation
-CommandId $runPSCommand.CommandId CommandId -Details $true
-InstanceId 實例 ID | Select -ExpandProperty CommandPlugins
獲取 SSMDocumentDescription -名稱-Name "AWS-InstallApplication" Get-SSMDocumentDescription
-名稱“AWS-InstallApplication” | Select -ExpandProperty 參數 $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
-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 實例ID | Select -ExpandProperty CommandPlugins $installPSCommand = Send-SSMCommand -InstanceId instance-ID
-DocumentName "AWS-InstallPowerShellModule" -Parameter @{'source'='https://gallery.tec.net.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 $真
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.