title: Loading config data from json file in AWS template.yaml for deploying to AWS Lambda
body: <p>When deploying a simple function to AWS Lambda, I want to use a <code>config.json</code> (external file) to fill some of the fields of the <code>template.yaml</code> that I use to configure my AWS Lambda deployment. My directory structure is</p>
  <pre><code>my_project 
      my_package\
          my_source_code.py
      template.yaml
      samconfig.toml
      config.json
  </code></pre>
  <p>Here <code>samconfig.toml</code> contains some deployment parameters related to the environment from which I deploy, <code>template.yaml</code> contains all the resource definitions (e.g. <code>AWS::Serverless::Function</code>, <code>AWS::Serverless::Api</code>, and <code>AWS::ApiGateway::BasePathMapping</code>), and <code>config.json</code> contains some package dependent configuration settings, like the package version number or the service name for this particular package.</p>
  <p>What I want to do is to load the version number from <code>config.json</code> and pass it as an environmental variable for the <code>AWS::Serverless::Function</code>. But I cannot find a way for doing that. What I tried to do is this:</p>
  <pre class="lang-yaml prettyprint-override"><code># template.yaml
  Resources:
      my_lambda:
          Type: AWS::Serverless::Function
          Properties:
              Handler: ...
              Environment:
                  Variables:
                      VERSION: ${file(config.json):version_number}
  </code></pre>
  <p>where</p>
  <pre><code># config.json
  {
      &quot;version_number&quot;: &quot;1.0&quot;
  }
  </code></pre>
  <p>However that doesn't work and when I load <code>VERSION</code> from the environment, I get to see the string <code>&quot;${file(config.json):version_number}&quot;</code>.</p>
  <p>I cannot find any resource online describing how to do that (admitting that I find the AWS documentation hard to comprehend).</p>
  <p>I did find documentation on <a href="https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/continuous-delivery-codepipeline-parameter-override-functions.html#w2ab1c21c18b9" rel="nofollow noreferrer"><code>Fn::GetParam</code></a>, but that needs an artifact name to load the json data from and I don't know what that would be in my context.</p>
  <blockquote>
  <p>NOTE: I use AWS CLI to deploy to AWS cloud using <code>sam build --use-container --manifest &lt;path/to/requirements.txt&gt;</code> and <code>sam deploy --no-confirm-changeset</code> as build and deploy commands.</p>
  </blockquote>