title: AWS Step Function ContainerOverrides clearing out already defined environment variables
body: <p>I'm using an AWS Step Function to invoke a Fargate container. The ECS Task Definition has several environment variables defined, some with fixed values and some coming from Systems Manager Parameter Store. The State Machine adds one additional environment variable using <code>ContainerOverrides</code>.</p>
  <p>Unfortunately this seems to replace, not add to, the environment variables specified within the task definition.</p>
  <p>If I don't define any environment variables in the step definition, then those from the task definition exist at runtime. If I define even one variable at the step definition, then only those from the step definition exist at runtime.</p>
  <p>How can I get Fargate/ECS/Step Functions to merge the environment variable instead of replacing all?</p>
  <p><strong>State Machine</strong></p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;Comment&quot;: &quot;Sample State Machine&quot;,
    &quot;StartAt&quot;: &quot;Prerequisites&quot;,
    &quot;States&quot;: {
      &quot;Prerequisites&quot;: {
        &quot;Type&quot;: &quot;Task&quot;,
        &quot;Resource&quot;: &quot;arn:aws:states:::ecs:runTask.sync&quot;,
        &quot;Parameters&quot;: {
          &quot;Cluster&quot;: &quot;arn:aws:ecs:us-west-2:1232123123:cluster/step-function-executor&quot;,
          &quot;TaskDefinition&quot;: &quot;step-function-generic-script-executor&quot;,
          &quot;LaunchType&quot;:&quot;FARGATE&quot;,
          &quot;NetworkConfiguration&quot;: {
            &quot;AwsvpcConfiguration&quot; : {
              &quot;AssignPublicIp&quot; : &quot;DISABLED&quot;,
              &quot;SecurityGroups&quot; : [
                &quot;sg-123&quot;,
                &quot;sg-456&quot;
              ],
              &quot;Subnets&quot; : [
                &quot;subnet-123&quot; ,
                &quot;subnet-456&quot;
              ]
            }
          },
          &quot;Overrides&quot;: {
            &quot;ContainerOverrides&quot;: [
              {
                &quot;Name&quot;: &quot;step-function-generic-script-container&quot;,
                &quot;Environment&quot;: [ 
                  {
                    &quot;Name&quot;: &quot;STEP_SCRIPT_NAME&quot;,
                    &quot;Value&quot;: &quot;db-daily-backup-01-prereq&quot;
                  }
                ]
              }
            ]
          }
        },
        &quot;End&quot;: true
      }
    }
  }
  </code></pre>
  <p><strong>Task Definition</strong></p>
  <p><a href="https://i.stack.imgur.com/sBivC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sBivC.png" alt="ECS Container Definition for Task Definition" /></a></p>