Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
988 views
in Technique[技术] by (71.8m points)

windows - How to get AWS command line interface to work in cygwin

I installed the AWS command line interface on my Windows 7 box, and it worked immediately when I called commands from a DOS shell.

But DOS, the worst language ever invented, is hideous for any serious scripting. So, I would like to to use the AWS CLI from bash via cygwin.

In my case, the installed AWS CLI is the Windows version. In principle, that should not be a problem because Windows commands are executable from cygwin. (cygwin includes your Windows environmental variables, such as PATH, in its own environment.)

Unfortunately, when I first tried to execute an AWS CLI command from cygwin/bash, I got an error:

$ aws s3 cp code.tgz s3://xyz/
upload failed: .code.tgz to s3://xyz/code.tgz
Unable to locate credentials

This error is likely because the AWS CLI is looking in the wrong directory for the credentials file. On Windows, it expects that file to be in %UserProfile%.aws and in unix in ~/.aws.

One hack work around is that in my home directory I created a new file named config_credentials which contains a union of the contents of that directory's files config and credentials. I then made a new Windows System env var named AWS_CONFIG_FILE whose value is the path to config_credentials. Success: AWS CLI commands issued from cygwin now work.

I am wondering if there is a better solution?

I am curious why AWS CLI initially failed to search in the correct home directory for the config and credentials files. I also wonder if there is a way to correct that (this would eliminate the need for the AWS_CONFIG_FILE env var).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had the same problem. I got around it by installing a new copy of AWSCLI within Cygwin. You first need to install the "curl" and "python" Cygwin packages, then you can install AWSCLI as follows:

$ curl -O https://bootstrap.pypa.io/get-pip.py
$ python get-pip.py
$ pip install awscli

If you're running bash, and you've previously executed the Windows AWS command line, you need to clear the cached path as follows:

$ hash -d aws

"aws --version" will then look similar to this:

aws-cli/1.8.1 Python/2.7.10 CYGWIN_NT-10.0/2.2.1(0.289/5/3)

as opposed to the Windows command line output, which looks similar to this:

aws-cli/1.8.1 Python/2.7.9 Windows/8

I'm now able to do "aws configure" under Cygwin, and everything works as it should.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...