title: Installing AWS CLI Version 2 in GitLab-Runner
body: <p>In-order to deploy my <code>Spring-Boot</code> application into <code>AWS ECS</code>, I have the need of installing <code>AWS CLI Version 2</code> into my <code>GitLab-Runner</code> which is running in <code>AWS EC2</code> Linux based <code>AMI</code>. I will add below the scripts and stage used to install <code>AWS CLI version 2</code>.</p>
  <p>This is the deploy stage and the image used.</p>
  <pre><code>deploy:
    image: alpine:3.11
    stage: deploy
    tags:
      - demo-ci
    script:
  </code></pre>
  <p>Below I mentioned the script used to install <code>AWS CLI Version 2</code> within the above mentioned stage.</p>
  <pre><code>curl &quot;https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip&quot; -o &quot;awscliv2.zip&quot;
  unzip awscliv2.zip
  ./aws/install
  aws --version
  </code></pre>
  <p>When I am running the script, I get the following issue.</p>
  <pre><code>$ ./aws/install
  ./aws/install: line 78: /builds/sl-psf/SpringDemoECS/aws/dist/aws: not found
  You can now run: /usr/local/bin/aws --version
  $ aws --version
  /bin/sh: eval: line 130: aws: not found
  </code></pre>
  <p>Even though it is mentioned to try <code>/usr/local/bin/aws --version</code>, it doesn't work either.</p>
  <p>However there is a workaround and it solved the issue and I will put the code below for that.</p>
  <pre><code>variables:
    REGION: &quot;us-east-2&quot;
    REPOSITORY_URL: &quot;############.dkr.ecr.us-east-2.amazonaws.com&quot;
    IMAGE_TAG: &quot;demo-app:0.1&quot;
    GLIBC_VER: &quot;2.31-r0&quot;
  
  
  [......]
  
  docker-deploy:
    image: alpine:3.11
    stage: deploy
    script:
      - apk add --no-cache python3 py3-pip binutils curl
      - curl -sL https://alpine-pkgs.sgerrand.com/sgerrand.rsa.pub -o /etc/apk/keys/sgerrand.rsa.pub
      - curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-${GLIBC_VER}.apk
      - curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-bin-${GLIBC_VER}.apk
      - curl -sLO https://github.com/sgerrand/alpine-pkg-glibc/releases/download/${GLIBC_VER}/glibc-i18n-${GLIBC_VER}.apk
      - apk add --no-cache glibc-${GLIBC_VER}.apk glibc-bin-${GLIBC_VER}.apk glibc-i18n-${GLIBC_VER}.apk
      - /usr/glibc-compat/bin/localedef -i en_US -f UTF-8 en_US.UTF-8
      - curl -sL https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip
      - unzip awscliv2.zip
      - aws/install
      - rm -rf awscliv2.zip aws /usr/local/aws-cli/v2/*/dist/aws_completer /usr/local/aws-cli/v2/*/dist/awscli/data/ac.index /usr/local/aws-cli/v2/*/dist/awscli/examples glibc-*.apk
      - apk --no-cache del binutils curl
      - rm -rf /var/cache/apk/*
      - aws --version
  </code></pre>
  <p>I don't think this is the optimal way to install <code>AWS CLI Version 2</code>. It was pretty difficult to do this task and there are various ways suggested. I think that this is a common issue lots of people might have faced. My question is that is there a better way to achieve this or if so then what would be the way?</p>