Skip to main content

GitHub Action: aws-region-reduction-map

Converts AWS region names from full names to abbreviations

Introduction

Converts AWS region names from full names to either "fixed" (always 3 characters) or "short" (usually 4 or 5 characters) abbreviations, following the same map as https://github.com/cloudposse/terraform-aws-utils

Short abbreviations are generally the same as official AWS availability zone IDs.

Generally, AWS region names have 3 parts and the "fixed" abbreviation is the first character of each part. Exceptions (due to collisions):

  • Africa and China use second letter of first part.
  • ap-south-1 is shortened to as0 to avoid conflict with ap-southeast-1
  • cn-north-1 is shortened to nn0 to avoid conflict with cn-northwest-1

You should be able to list all regions with this command:

aws ec2 describe-regions --all-regions --query "Regions[].{Name:RegionName}" --output text

but actually it leaves out GovCloud and China See https://github.com/jsonmaur/aws-regions for more complete list

longfixedshort
ap-east-1ae1ape1
ap-northeast-1an1apne1
ap-northeast-2an2apne2
ap-northeast-3an3apne3
ap-south-1as0aps1
ap-southeast-1as1apse1
ap-southeast-2as2apse2
ca-central-1cc1cac1
eu-central-1ec1euc1
eu-north-1en1eun1
eu-south-1es1eus1
eu-west-1ew1euw1
eu-west-2ew2euw2
eu-west-3ew3euw3
af-south-1fs1afs1
us-gov-east-1ge1usge1
us-gov-west-1gw1usgw1
me-south-1ms1mes1
cn-north-1nn0cnn1
cn-northwest-1nn1cnnw1
sa-east-1se1sae1
us-east-1ue1use1
us-east-2ue2use2
us-west-1uw1usw1
us-west-2uw2usw2

Usage

Convert AWS region (ex.: us-west-2) to fixed abbreviation - will be uw2.

  name: Pull Request
on:
pull_request:
branches: [ 'main' ]
types: [opened, synchronize, reopened, closed, labeled, unlabeled]

jobs:
context:
runs-on: ubuntu-latest
steps:
- uses: cloudposse/github-action-aws-region-reduction-map@main
id: aws_map
with:
region: 'us-west-2'
## Format can be skipped - default format would be `fixed` if region is long
format: 'fixed'

outputs:
result: ${{ steps.aws_map.outputs.result }}

Convert AWS region (ex.: us-west-2) to short abbreviation - will be usw2.

  name: Pull Request
on:
pull_request:
branches: [ 'main' ]
types: [opened, synchronize, reopened, closed, labeled, unlabeled]

jobs:
context:
runs-on: ubuntu-latest
steps:
- uses: cloudposse/github-action-aws-region-reduction-map@main
id: aws_map
with:
region: 'us-west-2'
format: 'short'

outputs:
result: ${{ steps.aws_map.outputs.result }}

Convert short AWS region (ex.: usw2) to long abbreviation - will be us-west-2.

  name: Pull Request
on:
pull_request:
branches: [ 'main' ]
types: [opened, synchronize, reopened, closed, labeled, unlabeled]

jobs:
context:
runs-on: ubuntu-latest
steps:
- uses: cloudposse/github-action-aws-region-reduction-map@main
id: aws_map
with:
region: 'usw2'
format: 'long'

outputs:
result: ${{ steps.aws_map.outputs.result }}

Convert fixed AWS region (ex.: uw2) to long abbreviation - will be us-west-2.

  name: Pull Request
on:
pull_request:
branches: [ 'main' ]
types: [opened, synchronize, reopened, closed, labeled, unlabeled]

jobs:
context:
runs-on: ubuntu-latest
steps:
- uses: cloudposse/github-action-aws-region-reduction-map@main
id: aws_map
with:
region: 'uw2'
format: 'long'

outputs:
result: ${{ steps.aws_map.outputs.result }}

Inputs

NameDescriptionDefaultRequired
formatFormat convert to. Valid values ('long', 'short', 'fixed').
If empty short and fixed inputs are converted to long, long inputs are converted to fixed.
N/Afalse
regionInput region codeN/Atrue

Outputs

NameDescription
resultConverted AWS region