title: Use output of one stack as environment variable for lambda in other stack with SAM or Cloudformation
body: <p>I want to use the exported output of one cloudformation stack as environment variable for a lambda in an other stack. </p>
  
  <p>Scenario:</p>
  
  <ul>
  <li>Stack1: QueueStack - Contains an sqs queue 'myQueue'. The stack exports the output of the queueUrl: <code>"${AWS::StackName}-myQueueUrl"</code></li>
  <li>Stack2: LambdaStack - Contains the lambda function that will put something on this queue. The lambda function has an env. variable 'QUEUE_URL' that should contain the url of the queue. I want to dynamically use the Url outputted by the QueueStack. Something in the likes of:</li>
  </ul>
  
  <pre><code>   Type: AWS::Lambda::Function
     Properties: 
       Environment:
           Variables:
               QUEUE_URL: 
               - Fn::ImportValue:
                   Fn::Sub: "${QueueStackParameter}-myQueueUrl"
  </code></pre>
  
  <p>However this is not possible since environments variables can only be strings.</p>
  
  <p>How can I use the exported output of one cloudformation stack as environment variable for a lambda in an other stack without cloudformation complaining that env vars have to be a string?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>When writing it like this, it does work:</p>
  
  <pre><code>  QUEUE_URL: !Join
    - ''
    - - "Fn::ImportValue":
          "Fn::Sub": "${QueueStackParameter}-myQueueUrl"
  </code></pre>
  
  <p>However when using the normal <code>ImportValue</code> syntax, it does not work:</p>
  
  <pre><code>  QUEUE_URL:
      - Fn::ImportValue:
          Fn::Sub: "${QueueStackParameter}-myQueueUrl"
  </code></pre>
  
  <p>CloudFormation then returns the following status reason:
  <code>Value of property Variables must be an object with String (or simple type) properties</code></p>