title: Parsing JSON dict of CloudFormation parameters for '--parameter-overrides'
body: <p>I'm using AWS CloudFormation at the moment, and I need to parse out parameters due to differences between stack creation and deployment. Command <code>aws cloudformation create</code> accepts a JSON file, but <code>aws cloudformation deploy</code> only accepts inlined application parameters of <code>Key=Value</code> type.</p>
  <p>I have this JSON file:</p>
  <pre><code>[
      {
          &quot;ParameterKey&quot;: &quot;EC2KeyPair&quot;,
          &quot;ParameterValue&quot;: &quot;$YOUR_EC2_KEY_PAIR&quot;
      },
      {
          &quot;ParameterKey&quot;: &quot;SSHLocation&quot;,
          &quot;ParameterValue&quot;: &quot;$YOUR_SSH_LOCATION&quot;
      },
      {
          &quot;ParameterKey&quot;: &quot;DjangoEnvVarDebug&quot;,
          &quot;ParameterValue&quot;: &quot;$YOUR_DJANGO_ENV_VAR_DEBUG&quot;
      },
      {
          &quot;ParameterKey&quot;: &quot;DjangoEnvVarSecretKey&quot;,
          &quot;ParameterValue&quot;: &quot;$YOUR_DJANGO_ENV_VAR_SECRET_KEY&quot;
      },
      {
          &quot;ParameterKey&quot;: &quot;DjangoEnvVarDBName&quot;,
          &quot;ParameterValue&quot;: &quot;$YOUR_DJANGO_ENV_VAR_DB_NAME&quot;
      },
      {
          &quot;ParameterKey&quot;: &quot;DjangoEnvVarDBUser&quot;,
          &quot;ParameterValue&quot;: &quot;$YOUR_DJANGO_ENV_VAR_DB_USER&quot;
      },
      {
          &quot;ParameterKey&quot;: &quot;DjangoEnvVarDBPassword&quot;,
          &quot;ParameterValue&quot;: &quot;$YOUR_DJANGO_ENV_VAR_DB_PASSWORD&quot;
      },
      {
          &quot;ParameterKey&quot;: &quot;DjangoEnvVarDBHost&quot;,
          &quot;ParameterValue&quot;: &quot;$YOUR_DJANGO_ENV_VAR_DB_HOST&quot;
      }
  ]
  </code></pre>
  <p>And I want to turn it into this:</p>
  <pre><code>'EC2KeyPair=$YOUR_EC2_KEY_PAIR SSHLocation=$YOUR_SSH_LOCATION DjangoEnvVarDebug=$YOUR_DJANGO_ENV_VAR_DEBU
  G DjangoEnvVarSecretKey=$YOUR_DJANGO_ENV_VAR_SECRET_KEY DjangoEnvVarDBName=$YOUR_DJANGO_ENV_VAR_DB_NAME D
  jangoEnvVarDBUser=$YOUR_DJANGO_ENV_VAR_DB_USER DjangoEnvVarDBPassword=$YOUR_DJANGO_ENV_VAR_DB_PASSWORD Dj
  angoEnvVarDBHost=$YOUR_DJANGO_ENV_VAR_DB_HOST'
  </code></pre>
  <p>This would be the equivalent Python code:</p>
  <pre class="lang-py prettyprint-override"><code>thing = json.load(open('stack-params.example.json', 'r'))
  convert = lambda item: f'{item[&quot;ParameterKey&quot;]}={item[&quot;ParameterValue&quot;]}'
  
  &gt;&gt;&gt; print(list(map(convert, thing)))                 
  ['EC2KeyPair=$YOUR_EC2_KEY_PAIR', 'SSHLocation=$YOUR_SSH_LOCATION', 'DjangoEnvVarDebug=$YOUR_DJANGO_ENV_V
  AR_DEBUG', 'DjangoEnvVarSecretKey=$YOUR_DJANGO_ENV_VAR_SECRET_KEY', 'DjangoEnvVarDBName=$YOUR_DJANGO_ENV_
  VAR_DB_NAME', 'DjangoEnvVarDBUser=$YOUR_DJANGO_ENV_VAR_DB_USER', 'DjangoEnvVarDBPassword=$YOUR_DJANGO_EN$
  _VAR_DB_PASSWORD', 'DjangoEnvVarDBHost=$YOUR_DJANGO_ENV_VAR_DB_HOST']
  
  &gt;&gt;&gt; ' '.join(map(convert, thing))
  'EC2KeyPair=$YOUR_EC2_KEY_PAIR SSHLocation=$YOUR_SSH_LOCATION DjangoEnvVarDebug=$YOUR_DJANGO_ENV_VAR_DEBU
  G DjangoEnvVarSecretKey=$YOUR_DJANGO_ENV_VAR_SECRET_KEY DjangoEnvVarDBName=$YOUR_DJANGO_ENV_VAR_DB_NAME D
  jangoEnvVarDBUser=$YOUR_DJANGO_ENV_VAR_DB_USER DjangoEnvVarDBPassword=$YOUR_DJANGO_ENV_VAR_DB_PASSWORD Dj
  angoEnvVarDBHost=$YOUR_DJANGO_ENV_VAR_DB_HOST'
  </code></pre>
  <p>I have this little snippet:</p>
  <pre class="lang-sh prettyprint-override"><code>$ cat stack-params.example.json | jq '.[] | &quot;\(.ParameterKey)=\(.ParameterValue)&quot;'
  &quot;EC2KeyPair=$YOUR_EC2_KEY_PAIR&quot;
  &quot;SSHLocation=$YOUR_SSH_LOCATION&quot;
  &quot;DjangoEnvVarDebug=$YOUR_DJANGO_ENV_VAR_DEBUG&quot;
  &quot;DjangoEnvVarSecretKey=$YOUR_DJANGO_ENV_VAR_SECRET_KEY&quot;
  &quot;DjangoEnvVarDBName=$YOUR_DJANGO_ENV_VAR_DB_NAME&quot;
  &quot;DjangoEnvVarDBUser=$YOUR_DJANGO_ENV_VAR_DB_USER&quot;
  &quot;DjangoEnvVarDBPassword=$YOUR_DJANGO_ENV_VAR_DB_PASSWORD&quot;
  &quot;DjangoEnvVarDBHost=$YOUR_DJANGO_ENV_VAR_DB_HOST&quot;
  </code></pre>
  <p>But I'm not sure how to join the strings together. I was looking at reduce but I think it only works on lists, and streams of strings aren't lists. So I'm thinking the correct approach is to convert the key : value association into 'key=value' strings within the list, then join altogether, though I have trouble working with the regex. Does anybody have any tips?</p>