CircleCI-Public/aws-ecs-orb

Variable interpolation in overrides JSON

nford opened this issue · 3 comments

nford commented

Orb version:

2.2.1

What happened:

...
environment:
      CLUSTER_NAME: foo-cluster
      CONTAINER_NAME: rails
    steps:
      - aws-cli/install
      - aws-authenticate
      - run:
          command: |
            aws sts get-caller-identity
- aws-ecs/run-task:
          cluster: '${CLUSTER_NAME}'
          overrides: '{"containerOverrides":[{"name": "${CONTAINER_NAME}", "environment": [{"name": "RUN_DB_MIGRATIONS","value": "true"}]}]}' 
...

An error occurred (InvalidParameterException) when calling the RunTask operation: name must match ^[a-zA-Z0-9\-_]+$

The same ENV VAR is used elsewhere without issue. If I replace ${CONTAINER_NAME} with the relevant string it works without issue. The Orb does not seem to interpolate the value within this JSON.

Expected behavior:

name value should be populated

Additional Information:

I ran into this exact issue today. Are you already working on a PR? If not I'll submit something.

brivu commented

@jeffreymlewis,

I've been working on this all day to figure it out but it seems like doing a eval echo on the overrides parameter is causing more issues, even without expanding an environment variable within the json. Here's the error I am getting when trying to run do so:

Error parsing parameter '--overrides': Invalid JSON: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
JSON received: {containerOverrides:[{name: sleep, memory: 512}]}

I'll be checking in with my team to see if there's any workarounds but if you can think of one, feel free to let me know.

Best,
Brian

Escaping the double-quotes would work, but it's ugly and makes this a breaking change. 🙁

Sorry I can't be more help. Unfortunately I couldn't use this orb in my current project (for other reasons) and never fully implemented this solution.

Here's how I was testing variable expansion.

#!/bin/bash

json='{\"containerOverrides\":[{\"name\": \"${CONTAINER_NAME}\", \"environment\": [{\"name\": \"RUN_DB_MIGRATIONS\",\"value\": \"true\"}]}]}'

json_eval=$(eval echo \"$json\")

echo $json_eval