ElasticThoughts
ElasticThoughts

Reputation: 3477

AWS CLI S3 copy (cp) command return 0 (zero) status code on both successful and unsuccessful attempts - Is this correct behavior?

I'm running a simple S3 copy command using the AWS command line tools. I have purposely entered a non-existent bucket name to test failures and handle them accordingly. However my return code is 0 (zero) on both successfully and non-successful copies to S3. Is this normal behavior or a bug? If this is normal, then how can I capture errors without having to inspect (i.e. grep) the standard output for string values (i.e. "upload failed")?

Successful copy

[ec2-user@ip-10-0-10-68 ~]$ aws s3 cp puppetmaster-bootstrap.sh s3://puppet-enterprise
upload: ./puppetmaster-bootstrap.sh to s3://puppet-enterprise/puppetmaster-bootstrap.sh
[ec2-user@ip-10-0-10-68 ~]$ echo $?
0

Unsuccessful copy

[ec2-user@ip-10-0-10-68 ~]$ aws s3 cp puppetmaster-bootstrap.sh s3://puppe-enterprise | tee -a ${LOGFILE}
upload failed: ./puppetmaster-bootstrap.sh to s3://puppe-enterprise/puppetmaster-bootstrap.sh A    client error (NoSuchBucket) occurred when calling the PutObject operation: The specified bucket does not exist
[ec2-user@ip-10-0-10-68 ~]$ echo $?
0

Using CLI version:

[ec2-user@ip-10-0-10-68 ~]$ aws --version
aws-cli/1.3.17 Python/2.6.9 Linux/3.10.35-43.137.amzn1.x86_64

Upvotes: 1

Views: 4980

Answers (2)

V.B
V.B

Reputation: 57

First thing , the way you are trying to capture the error is not correct, use pipe status and second, on AWS there is no direct way to get the error rather you can check with the file exists strategy

Upvotes: 0

Ryan Parman
Ryan Parman

Reputation: 6945

Sounds like this should be posted to their GitHub Issues page.

Upvotes: 3

Related Questions