AWS Cli in Windows wont upload file to s3 bucket

末鹿安然 提交于 2019-12-06 08:08:56

问题


Windows server 12r2 with python 2.7.10 and the aws cli tool installed. The following works:

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

I can upload that file without problem. What I want to do is upload a file from a mapped drive to an s3 bucket, so I tried this:

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

and it works.

Now what I want to do and cannot figure out is how to not specify, but let it grab all file(s) so I can schedule this to upload the contents of a directory to my s3 bucket. I tried this:

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

and I get this error "TOO FEW ARGUMENTS"

Nearest I can guess it's mad I'm not putting a specific file to send up, but I don't want to do that, I want to automate all things.

If someone could please shed some light on what I'm missing I would really appreciate it.

Thank you


回答1:


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

This is because, in you command, double-quote(") is escaped with backslash(\), so local path(s:\path\..\..\) is not parsed correctly.

What you need to do is to escape backslash with double backslashes, i.e. :

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




回答2:


Alternatively you can try 'mc' which comes as single binary is available for windows both 64bit and 32bit. 'mc' implements mirror, cp, resumable sessions, json parseable output and more - https://github.com/minio/mc

  • 64-bit from https://dl.minio.io/client/mc/release/windows-amd64/mc.exe
  • 32-bit from https://dl.minio.io/client/mc/release/windows-386/mc.exe



回答3:


In case this is useful for anyone else coming after me: Add some extra spaces between the source and target. I've been beating my head against running this command with every combination of single quotes, double quotes, slashes, etc:

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

And it would give me: "aws: error: too few arguments" Every. Single. Way. I. Tried.

So finally saw the --debug option in aws s3 cp help so ran it again this way:

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

And this was the relevant debug line:

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

I have no idea where \xc2\xa0 came from in between source and target, but there it is! Updated the line to add a couple extra spaces and now it runs without errors:

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



回答4:


Use aws s3 sync instead of aws s3 cp to copy the contents of a directory.




回答5:


I faced the same situation. Let share two scenarios I had tried to check the same code.

  1. Within bash please make sure you have AWS profile in place (use $aws configure). Also, make sure you use a proper proxy if applicable.

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

it worked.

  1. Within a perl script

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

I enclosed it within "" and it was successful. Let me know if this works out for you.



来源:https://stackoverflow.com/questions/34535969/aws-cli-in-windows-wont-upload-file-to-s3-bucket

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!