title: Accessing two tables from different accounts within the same lambda function
body: <p>Is it possible to access two tables within one lambda function while one of the tables is in the same account as the lambda function and the other is in another account?</p>
  
  <p>I've seen articles on <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_cross-account-with-roles.html" rel="noreferrer">cross-account access delegation</a> using IAM roles here and there. But I'm not sure how the code should reflect accessing a resource from another account. This is how I usually access some DynamoDb table:</p>
  
  <pre><code>const dynamodb = new AWS.DynamoDB();
  const docClient = new AWS.DynamoDB.DocumentClient({ service: dynamodb });
  docClient
    .get({
      TableName: 'SomeTable',
      Key: { id }
    });
  </code></pre>
  
  <p>Looking at the <a href="https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#constructor-property" rel="noreferrer">documentation</a>, there's no mention of account ID in the constructor. So I'm not sure how I can have two connections at the same time, one pointing to one account and the other pointing to another account!?</p>