Fixing a Github Action error "botocore.awsrequest.AWSRequest" "exit code 255"

The other day I suddenly started hitting an error in my Github Actions that deploy static Hugo sites to S3:

<botocore.awsrequest.AWSRequest object at 0x7fbfb444e160>
Error: Process completed with exit code 255.

For some reason setting an env variable called AWS_EC2_METADATA_DISABLED to true fixes this error.

E.g. your Github Action YAML might look like this:

name: Build and Deploy

on: push

jobs:
  build:
    name: Build and Deploy
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - name: Install Hugo
        run: |
          HUGO_DOWNLOAD=hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz
          wget https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/${HUGO_DOWNLOAD}
          tar xvzf ${HUGO_DOWNLOAD} hugo
          mv hugo $HOME/hugo
        env:
          HUGO_VERSION: 0.71.0
      - name: Hugo Build
        run: $HOME/hugo -v
      - name: Deploy to S3
        if: github.ref == 'refs/heads/master'
        run: aws s3 sync public/ s3://{s3-bucket-name}/ --delete --acl=public-read && aws cloudfront create-invalidation --distribution-id={cloudfront-distribution-id} --paths='/*'
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          AWS_EC2_METADATA_DISABLED: true

The key bit for avoiding this error is:

env:
    AWS_EC2_METADATA_DISABLED: true

Tech mentioned