aws cli – GitHub Action – AWS CLI

aws cli – GitHub Action – AWS CLI

aws-cli package is available in GitHub-hosted virtual environments. (aws-cli/1.16.266 Python/2.7.12 Linux/4.15.0-1057-azure botocore/1.13.2)

Make sure to set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in environment variables. You can use Github secrets to store these credentials securely.

- name: Upload to S3
      run: |
        aws s3 sync ./build s3://test-bucket
      env:
        AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
        AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
        AWS_DEFAULT_REGION: ap-south-1

From GitHub documentation the aws-cli is already available directly on the host image.

It would be nice if this information were available on the deprecation notice
¯_(ツ)_/¯

aws cli – GitHub Action – AWS CLI

An alternative to default awscli, or using third party actions is to configure python and install the awscli at the time of the build:

name: Sync to S3 bucket
on: [push]
jobs:
  sync:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: 3.7
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install awscli
      - run: aws s3 sync builddir s3://foobar --region eu-west-1 --cache-control max-age=0 --acl public-read --delete
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

Github Actions > Building and testing Python docs on Github https://docs.github.com/en/actions/guides/building-and-testing-python

Related Posts

Leave a Reply

Your email address will not be published.