400 Bad Request in Gitlab Pipeline When Using AWS CLI ($ aws s3 cp s3://xxxx/abc ./abc)

Problem to solve

I want to fetch key file by aws cli in runner.

...

deploy-dev-site:
  stage: deploy-dev
  image: zulhfreelancer/aws-cli-v2-on-ubuntu
  before_script:
    - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )'
    - eval $(ssh-agent -s)
    - mkdir -p ~/.ssh
    - aws --profile default configure set aws_access_key_id "$AWS_ACCESS_KEY_ID"
    - aws --profile default configure set aws_secret_access_key "$AWS_SECRET_ACCESS_KEY"
    - aws --profile default configure set region "$AWS_REGION"
    - aws configure list
    - aws s3 cp s3://xxxx/abc.key ~/.ssh/abc.key --region "$AWS_REGION"
  script:
  ...
  only:
    - dev
    - main
  tags:
    - saas-linux-medium-amd64

the access keys are worked in my local environment, but result in 400 Bad Request on Gitlab Runner container.

Versions

  • Self-managed
  • GitLab.com SaaS
  • Self-hosted Runners

Versions

  • GitLab (Web: /help or self-managed system information): GitLab Enterprise Edition 17.0.0-pre f5564d18374
  • GitLab Runner, if self-hosted (Web /admin/runners or CLI gitlab-runner --version): saas-linux-medium-amd64
Running with gitlab-runner 16.11.0~pre.21.gaa21be2d (aa21be2d)
  on green-5.saas-linux-medium-amd64.runners-manager.gitlab.com/default g2po1APs, system ID: s_dcb821077a82
  feature flags: FF_USE_IMPROVED_URL_MASKING:true
...