title: Multiple API Gateway instances, one lambda function
body: <p>I am trying to build a system where <strong>multiple APIs gateway</strong> instances should execute <strong>the same lambda function</strong>. </p>
  
  <p>My problem is that I would like to change only the lambda configuration in function of the API gateway used. </p>
  
  <p>Let's take the name of a database as an example that should change if the lambda is being triggered from one API or the other.</p>
  
  <p><strong><em>Example:</em></strong></p>
  
  <pre><code>API Gateways:
  https://my-first-api-gateway.execute-api.eu-west-1.amazonaws.com
  https://my-second-api-gateway.execute-api.eu-west-1.amazonaws.com
  </code></pre>
  
  <p>I then have one lambda function being called by the two APIs: <code>say_hello</code>.</p>
  
  <p><strong>This function has to retrieve a quote from a database. If the function has been called from <code>my-first-api-gateway</code> the lambda function has to use <code>my_first_database</code> and if the function has been called from <code>my-second-api-gateway</code>, it has to use <code>my_second_database</code>.</strong></p>
  
  <p>The only solution I came with is to deploy as many lambda functions as I have API Gateways. And then use environment variables to store my database name. </p>
  
  <p>I don't like my solution because when I update a single line of code I'll have to redeploy all of my lambda functions.. (if I have 300 different databases to use, that would mean to update 300 lambda functions at once..)</p>
  
  <p>Thank you for your ideas on this subject!</p>