title: Querying single item in DynamoDB using Lambda
body: <p>I have a table in DynamoDB that stores some data, the partition key -  username - gets stored as the CognitoUser name along with a sort key provided by the user (Sort key is "Code") -  these make up the primary key. </p>
  
  <p>I want to query a single Item in DynamoDB that matches the primary key. </p>
  
  <p>Here is my Lambda function;</p>
  
  <pre><code>exports.handler = (event, context, callback) =&gt; {
      const type = event.type;
      if (type === 'all'){
          const params = {
              TableName: 'test-record'
          };
          dynamodb.scan(params,function(err,data){
              if(err){
                  console.log(err);
                  callback(err);
              }else{
                  console.log(data);
                  const items = data.Items.map(
                      (dataField) =&gt;{
                         return{
                             Date: dataField.Date.S,
                             Code: dataField.Code.S,
                             TelNumber: +dataField.TelNumber.N,
                             NameOfPerson: dataField.NameOfPerson.S,
                             FileNum: dataField.FileNum.S,
                             Purpose: dataField.Purpose.S,
                         };
                      }
                      );
                  callback(null,items);
              }
          });
      }else if(type == 'single'){
          const params = {
  
              Key: {
                  "username": {
                      S: dataField.username.S,
                  },
                  "Code": {
                      S: dataField.Code.S
                  }
              },
              TableName: "test-record"  
          };
          dynamodb.getItem(params, function(err,data){
              if(err){
                  console.log(err);
                  callback(err);
              }else{
                  console.log(data);
                  callback(null, data);
              }
          });
      }else{
          callback('Something went wrong');
      } };
  </code></pre>
  
  <p>If i hardcode "username" and "Code" in this function, it works and returns the correct data, but using the above pasted code gives me an error saying;</p>
  
  <pre><code>{ "errorMessage": "RequestId: c410e493-b774-11e7-a528-37d94b51b57b Process exited before completing request" }
  </code></pre>
  
  <p>Any ideas how to get items from DynamoDB  without having to hard them into Lambda?</p>