title: UnrecognizedClientException","errorMessage":"The security token included in the request is invalid when testing lambda function locally
body: <p>I am trying to use aws sam to invoke my lambda function locally for testing. The function reads an item from a dynamodb table. I have spin up a local dynamodb container where the desired table is created.</p>
  <p>Ran below commands to create a local dynamodb container.</p>
  <ol>
  <li>docker network create lambda-local</li>
  <li>docker run —-network=lambda-local —-name users -d -p 8000:8000 amazon/dynamodb-local</li>
  <li>aws dynamodb create-table --table-name employees --attribute-definitions AttributeName=name,AttributeType=S --key-schema AttributeName=name,KeyType=HASH --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 --endpoint-url=http://127.0.0.1:8000</li>
  </ol>
  <p>Then using below command I am able to verify that all is working fine as far as local dynamodb is concerned.</p>
  <ol>
  <li>aws dynamodb list-tables --endpoint-url http://localhsot:8000</li>
  </ol>
  <p>But then, when I try to run the below command, I get an error.</p>
  <pre><code>sam local invoke &lt;lambdaFunctionName&gt; --docker-network lambda-local
  </code></pre>
  <p>The error I get -</p>
  <pre><code>START RequestId: 043b493d-8457-43f1-8eeb-dc641ac3816f Version: $LATEST
  2021-10-27T08:17:00.778Z        043b493d-8457-43f1-8eeb-dc641ac3816f    ERROR   Invoke Error    
  {&quot;errorType&quot;:&quot;UnrecognizedClientException&quot;,&quot;errorMessage&quot;:&quot;The security token included in the request is invalid&quot;,
  &quot;code&quot;:&quot;UnrecognizedClientException&quot;,&quot;message&quot;:&quot;The security token included in the request is invalid&quot;,&quot;time&quot;:&quot;2021-10-27T08:17:00.775Z&quot;,&quot;requestId&quot;:&quot;NG2U0AEVI320VL5PLPTK8H3G63VV4KQNSO5AEMVJF66Q9ASUAAJG&quot;,&quot;statusCode&quot;:400,&quot;retryable&quot;:false,&quot;retryDelay&quot;:46.55385931289337,&quot;stack&quot;:[&quot;UnrecognizedClientException: The security token included in the request is invalid&quot;,&quot;    at Request.extractError (/var/runtime/node_modules/aws-sdk/lib/protocol/json.js:52:27)&quot;,&quot;    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:106:20)&quot;,&quot;    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:78:10)&quot;,&quot;    at Request.emit (/var/runtime/node_modules/aws-sdk/lib/request.js:688:14)&quot;,&quot;    at Request.transition (/var/runtime/node_modules/aws-sdk/lib/request.js:22:10)&quot;,&quot;    at AcceptorStateMachine.runTo (/var/runtime/node_modules/aws-sdk/lib/state_machine.js:14:12)&quot;,&quot;    at /var/runtime/node_modules/aws-sdk/lib/state_machine.js:26:10&quot;,&quot;    at Request.&lt;anonymous&gt; (/var/runtime/node_modules/aws-sdk/lib/request.js:38:9)&quot;,&quot;    at Request.&lt;anonymous&gt; (/var/runtime/node_modules/aws-sdk/lib/request.js:690:12)&quot;,&quot;    at Request.callListeners (/var/runtime/node_modules/aws-sdk/lib/sequential_executor.js:116:18)&quot;]}
  END RequestId: 043b493d-8457-43f1-8eeb-dc641ac3816f
  </code></pre>
  <p>What am I missing here ? Are there any other steps required to invoke a lambda function locally using sam and connect it to a locally running dynamodb container ?</p>
  <p>lambda code</p>
  <pre><code>var AWS = require('aws-sdk');
  AWS.config.update({region: 'us-east-1'});
  
  exports.lambdaHandler = async (event, context) =&gt; {
      const dynamoDB = new AWS.DynamoDB.DocumentClient();
      const params = {
          TableName: 'employees',
          Key: {
              name: &quot;naxi&quot;
          }
      };
  
      const result = await dynamoDB.get(params).promise();
      if (result.Item) {
          return result.Item;
      } else {
          return { error: 'Task not found.' };
      }
  };
  </code></pre>