簡體   English   中英

Windows 中的 AWS Cli 不會將文件上傳到 s3 存儲桶

[英]AWS Cli in Windows wont upload file to s3 bucket

安裝了 python 2.7.10 和 aws cli 工具的 Windows 服務器 12r2。 以下作品:

aws s3 cp c:\a\a.txt s3://path/

我可以毫無問題地上傳該文件。 我想要做的是將文件從映射驅動器上傳到 s3 存儲桶,所以我嘗試了這個:

aws s3 cp s:\path\file s3://path/

它有效。

現在我想做但無法弄清楚的是如何不指定,但讓它抓取所有文件,這樣我就可以安排將目錄的內容上傳到我的 s3 存儲桶。 我試過這個:

aws s3 cp "s:\path\..\..\" s3://path/ --recursive --include "201512"

我得到這個錯誤“參數太少”

最近我能猜到我沒有把一個特定的文件發送上去很生氣,但我不想那樣做,我想自動化所有的事情。

如果有人可以闡明我所缺少的東西,我將非常感激。

謝謝

如果這對跟隨我的其他人有用:在源和目標之間添加一些額外的空格。 我一直在努力反對使用單引號、雙引號、斜杠等的每種組合來運行此命令:

aws s3 cp /home/<username>/folder/ s3://<bucketID>/<username>/archive/ --recursive --exclude "*" --include "*.csv"

它會給我:“aws:錯誤:參數太少”每個。 單身的。 方法。 我試過。

所以終於在aws s3 cp help中看到了 --debug 選項,所以以這種方式再次運行它:

aws s3 cp /home/<username>/folder/ s3://<bucketID>/<username>/archive/ --recursive --exclude "*" --include "*.csv" --debug

這是相關的調試行:

MainThread - awscli.clidriver - DEBUG - Arguments entered to CLI: ['s3', 'cp', 'home/<username>/folder\xc2\xa0s3://<bucketID>/<username>/archive/', '--recursive', '--exclude', '*', '--include', '*.csv', '--debug']

我不知道\xc2\xa0在源和目標之間來自哪里,但它就在那里:更新了行以添加幾個額外的空格,現在它運行時沒有錯誤:

aws s3 cp /home/<username>/folder/   s3://<bucketID>/<username>/archive/ --recursive --exclude "*" --include "*.csv" 

aws s3 cp "s:\path\..\..\" s3://path/ --recursive --include "201512"太少

這是因為,在您的命令中,雙引號 ( " ) 使用反斜杠 ( \ ) 轉義,因此本地路徑 ( s:\path\..\..\ ) 未被正確解析。

你需要做的是用雙反斜杠轉義反斜杠,即:

aws s3 cp "s:\\path\\..\\..\\" s3://path/ --recursive --include "201512"

或者,您可以嘗試 'mc',它作為單個二進制文件可用於 64 位和 32 位 Windows。 'mc' 實現鏡像、cp、可恢復會話、json 可解析輸出等 - https://github.com/minio/mc

使用aws s3 sync而不是aws s3 cp來復制目錄的內容。

我遇到了同樣的情況。 讓我們分享兩個我曾嘗試檢查相同代碼的場景。

  1. 在 bash 中,請確保您有 AWS 配置文件(使用 $aws configure)。 另外,請確保您使用適當的代理(如果適用)。

$aws s3 cp s3://bucket/directory/ /usr/home/folder/ --recursive --region us-east-1 --profile yaaagy

有效。

  1. 在 perl 腳本中

    $cmd="$aws s3 cp s3://bucket/directory/ /usr/home/folder/ --recursive --region us-east-1 --profile yaaagy"

我把它括在“”中,它成功了。 讓我知道這是否適合您。

我最近遇到了同樣的問題, quiver 的回答——用雙反斜杠替換單反斜杠——解決了我遇到的問題。

這是我用來解決問題的 Powershell 代碼,使用 OP 的原始示例:

# Notice how my path string contains a mixture of single- and double-backslashes
$folderPath = "c:\\a\a.txt"
echo "`$folderPath = $($folderPath)"

# Use the "Resolve-Path" cmdlet to generate a consistent path string.
$osFolderPath = (Resolve-Path $folderPath).Path
echo "`$osFolderPath = $($osFolderPath)"

# Escape backslashes in the path string.
$s3TargetPath = ($osFolderPath -replace '\\', "\\")
echo "`$s3TargetPath = $($s3TargetPath)"

# Now pass the escaped string to your AWS CLI command.
echo "AWS Command = aws s3 cp `"s3://path/`" `"$s3TargetPath`""

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM