![](/img/trans.png)
[英]Upload file to S3 Bucket with AWS SDK NoSuchBucket error
[英]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
来复制目录的内容。
我遇到了同样的情况。 让我们分享两个我曾尝试检查相同代码的场景。
$aws s3 cp s3://bucket/directory/ /usr/home/folder/ --recursive --region us-east-1 --profile yaaagy
有效。
在 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.