Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aws s3 ls: An HTTP Client raised an unhandled exception: Invalid header value

I'm trying to implement a pipeline that package and copy Python code to S3 using Gitlab CI. Here is the job that is causing the problem:

package:
  stage: package
  image: python:3.8
  script:
    - apt-get update && apt-get install -y zip unzip jq
    - pip3 install awscli 
    - aws s3 ls
    - ./cicd/scripts/copy_zip_to_s3.sh
  only:
    refs:
      - developer

I want to mention that in the section before_script in .gitlab-ci.yml, I've already exported the AWS credentials (AWS SECRET ACCESS KEY, AWS_ACCESS_KEY_ID, etc) from Gitlab environment variables. I've checked thousands of times my credentials and they are totally correct. I want also to mention that the same script works perfectly for another project under the same group in Gitlab. Here is the error:

$ aws s3 ls
An HTTP Client raised an unhandled exception: Invalid header value b'AWS4-HMAC-SHA256 Credential=AKIAZXXXXXXXXXX\n/2020XX2/us-east-1/sts/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=ab53XX6eb72XXXXXX2152e4XXXX93b104XXXXXXX363b1da6f9XXXXX'
ERROR: Job failed: exit code 1

./cicd/scripts/copy_zip_to_s3.sh do the package and the copy, same error occurs when executing it, that's why I've added a simple aws command aws s3 ls to show that even a simple 'ls' is not working.

Any solutions, please? Thank you all in advance.

like image 775
Ouma Avatar asked Sep 02 '20 16:09

Ouma


People also ask

Why AWS CLI not working?

If the aws command cannot be found after first installing or updating the AWS CLI, you might need to restart your terminal for it to recognize any PATH updates. If the aws command cannot be found after first installing or updating the AWS CLI, it might not have been fully installed.

Can't connect to Endpoint URL AWS CLI?

You can get the "Could not connect to the endpoint URL" error if there's a typo or error in the specified Region or endpoint. Before you run the cp or sync command, be sure to confirm that the associated Region and S3 endpoint are written correctly.

How do I change to AWS command line?

To switch to a production role (AWS CLI)Create a new profile for the role in the . aws/config file in Unix or Linux, or the C:\Users\USERNAME\. aws\config file in Windows. The following example creates a profile called prodaccess that switches to the role ProductionAccessRole in the 123456789012 account.

Is not recognized as an internal or external command operable program or batch file AWS?

'aws' is not recognized as an internal or external command, operable program or batch file. This issue occurs when the path of the CLI installed path is not given along with aws command. 1) For Solution, enter CR with a Workaround if a direct Solution is not available.


1 Answers

This was because of an additional line added to AWS ACCESS KEY variable. Thanks to @jordanm

like image 85
Ouma Avatar answered Sep 28 '22 17:09

Ouma