How to use Environment Variables with Naming other Environment Variables?

Hello everyone!

I feel like I’m just missing something completely here with my configuration file. I’m currently attempting to setup my AWS profile through the circle.yml file.

Here’s what I have so far:

jobs:
  build:
    <<: *container_config
    steps:
      - checkout
      - run:
          name: Setup AWS profile
          command: |
            aws configure set aws_access_key_id ${CIRCLE_BRANCH^^}_AWS_ACCESS_KEY --profile $CIRCLE_BRANCH
            aws configure set aws_secret_access_key ${CIRCLE_BRANCH^^}_AWS_ACCESS_KEY --profile $CIRCLE_BRANCH
            aws configure set region us-east-1 --profile $CIRCLE_BRANCH
            echo 'export AWS_PROFILE="$CIRCLE_BRANCH"' >> $BASH_ENV
            source $BASH_ENV

I have an environment variable set in CircleCI as DEV_AWS_ACCESS_KEY, and the CIRCLE_BRANCH parameter is dev. I’m just unsure on how to reference an environment variable in another environment variable name:

aws configure set aws_access_key_id ${CIRCLE_BRANCH^^}_AWS_ACCESS_KEY

Obviously, the command above isn’t going to work since I’m not referencing the full value of “DEV_AWS_ACCESS_KEY” as an environment variable. Any pointers would be great!

I figured it out, turns out I can do something like this:

access_key = "${CIRCLE_BRANCH^^}_AWS_ACCESS_KEY"
aws configure set aws_access_key_id ${!access_key} --profile $CIRCLE_BRANCH

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.