title: Getting URL Parameter from API Gateway in Lambda
body: <p>I am hoping that someone can help me get a URL Parameter passed from the AWS API Gateway in Lambda. </p>
  
  <p>I am a little confused how to access this inside the Lambda code.</p>
  
  <p>For the API Gateway I have followed these steps:</p>
  
  <p>1) Went  to <strong>Resources -> Integration Request</strong></p>
  
  <p>2) Clicked on the plus icon next to templates dropdown </p>
  
  <p>3) Explicitly typed <strong>application/json</strong> in the content-type field </p>
  
  <p>4) For input mapping Entered:</p>
  
  <pre><code>{ "apiToken": "$input.params('apiToken')" }
  </code></pre>
  
  <p>So for clarification, How do I access the parameter <strong>apiToken</strong> in my Lambda Function?</p>
  
  <p>I have been looking at the walkthroughts and other docs for a while now and my brain is a little frazzled. </p>
  
  <p>I appreciate all help and feedback :)</p>
  
  <h1>Update</h1>
  
  <p>So, the issue seemed to be that the AWS website AJAX save did not save what I entered in the mapping (I am on hotel wifi so could be that).</p>
  
  <p>Now, When I test it I get:</p>
  
  <pre><code>Received event: { appToken: '123456' }
  </code></pre>
  
  <p>In the console log for lambda. However, When I go to the API Gateway, and deploy The response is:</p>
  
  <blockquote>
    <p>"errorMessage": "Process exited before completing request"</p>
  </blockquote>
  
  <p>Any Ideas?</p>
  
  <blockquote>
    <p>P.S The function works in the Lambda Console however, when I test it using Postman [POST + Param] it does not work, with the error message supplied just above</p>
  </blockquote>
  
  <h1>Update 2</h1>
  
  <p>Here is my Entire Lambda Function</p>
  
  <pre><code>    console.log('Loading event');
  var AWS = require('aws-sdk');
  var dynamodb = new AWS.DynamoDB({apiVersion: '2012-08-10'});
  var http = require('http');
  
  exports.handler = function(event, context) {
  
  
  
      var tableName = "clients";
  
      var appToken = event.params.appToken; //gr5f4sgnca25hki98
      dynamodb.getItem({
          TableName: tableName,
          Key: {
              ClientID: { S: appToken } }
  
      }, function (err, data)
  {
      if (err) {
         context.done(err);
      } else {
          var url = data.Item.url.S + data.Item.api.S;
          console.log(url);
          console.log('Received event:', event.params.appToken);
          http.get(url, function(res) {
              // Continuously update stream with data
              var body = '';
              res.on('data', function(d) {
                  body += d;
              });
              res.on('end', function() {
                  var result = body.replace('\\', '');
                  context.succeed(JSON.parse(result));
              });
              res.on('error', function(e) {
                  context.fail("Got error: " + e.message);
              });
          });
      }
      });
  };
  </code></pre>
  
  <p>In my test event I have:</p>
  
  <pre><code>{
      "method": "POST",
      "params": {
          "appToken": "gr5f4sgnca25hki98"
      }
  }
  </code></pre>
  
  <p>When I run this in Lambda the respnse works, it connects ro an external JSON file and returns it. </p>
  
  <p>However, In Postman I get the error: </p>
  
  <blockquote>
    <p>"errorMessage": "Process exited before completing request"</p>
  </blockquote>
  
  <p>Can anyone see why in the console it all works fine and when I try it out in deployment I still get the error?</p>
  
  <p>When I open XCODE and test this url with Alamofire I get this error (if it helps)</p>
  
  <blockquote>
    <p>Invalid Sequence around character 72</p>
  </blockquote>
  
  <h1>Update 3 (Test from API Console)</h1>
  
  <p>When tested from the API console, using: </p>
  
  <pre><code> {
  "method": "POST",
  "params": {
      "appToken": "gr5f4sgnca25hki98"
  }
  }
  </code></pre>
  
  <p>in the Request Body. I get:</p>
  
  <blockquote>
    <p>Request: /sendtoclient</p>
    
    <p>Status: 200</p>
    
    <p>Latency: 1839 ms</p>
  </blockquote>
  
  <h1>Response Body</h1>
  
  <blockquote>
    <p>{ "errorMessage": "Process exited before completing request" }</p>
  </blockquote>
  
  <h1>Response Headers</h1>
  
  <blockquote>
    <p>{"Content-Type":"application/json"}</p>
  </blockquote>
  
  <h1>Logs</h1>
  
  <pre><code>Execution log for request test-request
  Tue Mar 22 17:28:27 UTC 2016 : Starting execution for request:    test-invoke-request
  Tue Mar 22 17:28:27 UTC 2016 : HTTP Method: POST, Resource      Path: /sendtoclient
  Tue Mar 22 17:28:27 UTC 2016 : Method request path: {}
  Tue Mar 22 17:28:27 UTC 2016 : Method request query string:     {}
  Tue Mar 22 17:28:27 UTC 2016 : Method request headers: {}
  Tue Mar 22 17:28:27 UTC 2016 : Method request body before  transformations: {
  "method": "POST",
  "params": {
      "appToken": "gr5f4sgnca25hki98"
  }
  }
  Tue Mar 22 17:28:27 UTC 2016 : Endpoint request body after transformations: { "appToken": "" }
  Tue Mar 22 17:28:29 UTC 2016 : Endpoint response body before transformations: {"errorMessage":"Process exited before completing request"}
  Tue Mar 22 17:28:29 UTC 2016 : Endpoint response headers: {x-amzn-Remapped-Content-Length=0, x-amzn-RequestId=123456789, Connection=keep-alive, Content-Length=59, X-Amz-Function-Error=Unhandled, Date=Tue, 22 Mar 2016 17:28:29   GMT, Content-Type=application/json}
  Tue Mar 22 17:28:29 UTC 2016 : Method response body after transformations: {"errorMessage":"Process exited before completing request"}
  Tue Mar 22 17:28:29 UTC 2016 : Method response headers: {Content-Type=application/json}
  Tue Mar 22 17:28:29 UTC 2016 : Successfully completed execution
  Tue Mar 22 17:28:29 UTC 2016 : Method completed with status: 200
  </code></pre>
  
  <p>I'm not sure how to decipher this. Any help would be very much appreciated. I have however noticed this:</p>
  
  <pre><code> Endpoint request body after transformations: { "appToken": "" }
  </code></pre>
  
  <p>Which for some reason I feel may be significant </p>