title: Lambda function is not authorized to perform sts:AssumeRole
body: <p>I have a lambda function in account A trying to access resources from account B. Created a new lambda role with basic execution with access to upload logs to cloud watch.</p>
  
  <p>Here's my function code in Python 3.7:</p>
  
  <pre><code>import boto3
  
  allProfiles = ['account2']
  
  def lambda_handler(event, context):
  
      sts_connection = boto3.client('sts')
      acct_b = sts_connection.assume_role(
          RoleArn="arn:aws:iam::2222222222:role/role-on-source-account",
          RoleSessionName="account2"
      )
  
      for profiles in allProfiles:
          print("\nusing profile %s" % profiles)
          newMethod..
      return {
          'statusCode': 200,
          'body': json.dumps('Hello from Lambda!')
      }
  </code></pre>
  
  <p>Also modified the trust policy of the assumed role in account B as mentioned in documentation: <a href="https://aws.amazon.com/premiumsupport/knowledge-center/lambda-function-assume-iam-role/" rel="nofollow noreferrer">https://aws.amazon.com/premiumsupport/knowledge-center/lambda-function-assume-iam-role/</a></p>
  
  <blockquote>
    <p>ERROR: An error occurred (AccessDenied) when calling the AssumeRole
    operation: User:
    arn:aws:sts::11111111:assumed-role/lambda-role/lambda-function is not
    authorized to perform: sts:AssumeRole on resource:
    arn:aws:iam::2222222222:role/role-on-source-account"</p>
  </blockquote>
  
  <p>Note: I am able to run this in my local successfully but not in lambda.</p>