title: CredentialRetrievalError: Failed to refresh credentials
body: <p>For some reasons I'm parallely invoking a lambda function, for this I got the method <code>invoke</code> inside some function. An example is</p>
  <pre><code>import boto3 
  import json
  
  def some_function(param1, param2):
  
      # Example payload
      payload = {
      'body': '{&quot;key1&quot;: ' + f'&quot;{param1}&quot; , &quot;key2&quot;: ' + f'&quot;{param2}&quot;' + '}'
      }
      
      # Initialize a lambda client
      lambda_client = boto3.client('lambda')
      
      # Invoke lambda 
      response = lambda_client.invoke(
                  FunctionName='my_lambda_func',
                  Payload=json.dumps(payload).encode(),
              )
      
      # Retrieve body
      response = json.loads(response[&quot;Payload&quot;].read())
  
      # Some other things 
  
      return something
      
  </code></pre>
  <p>notice that <code>lambda_client</code> goes inside the function as it can't be pickled. Then, I call this function parallely</p>
  <pre><code>import multiprocessing 
  
  # Invoke lambda in parallel
  pool = multiprocessing.Pool(multiprocessing.cpu_count())
  result = pool.starmap(some_func, zip(list_of_param1, list_of_param2))
  </code></pre>
  <p>where size of <code>list_of_param1</code> and <code>list_of_param2</code> is approximately more than 100k items. I'm unable to end the process as it raises the following error</p>
  <pre><code>CredentialRetrievalError: Error when retrieving credentials from iam-role: Credential refresh failed, response did not contain: access_key, secret_key, token, expiry_time
  </code></pre>
  <p><strong>Full Traceback error</strong>:</p>
  <pre><code>File &quot;/home/miguel/python3/lib/python3.6/site-packages/botocore/client.py&quot;, line 337, in _api_call
      return self._make_api_call(operation_name, kwargs)
    File &quot;/home/miguel/python3/lib/python3.6/site-packages/botocore/client.py&quot;, line 643, in _make_api_call
      operation_model, request_dict, request_context)
    File &quot;/home/miguel/python3/lib/python3.6/site-packages/botocore/client.py&quot;, line 662, in _make_request
      return self._endpoint.make_request(operation_model, request_dict)
    File &quot;/home/miguel/python3/lib/python3.6/site-packages/botocore/endpoint.py&quot;, line 102, in make_request
      return self._send_request(request_dict, operation_model)
    File &quot;/home/miguel/python3/lib/python3.6/site-packages/botocore/endpoint.py&quot;, line 132, in _send_request
      request = self.create_request(request_dict, operation_model)
    File &quot;/home/miguel/python3/lib/python3.6/site-packages/botocore/endpoint.py&quot;, line 116, in create_request
      operation_name=operation_model.name)
    File &quot;/home/miguel/python3/lib/python3.6/site-packages/botocore/hooks.py&quot;, line 356, in emit
      return self._emitter.emit(aliased_event_name, **kwargs)
    File &quot;/home/miguel/python3/lib/python3.6/site-packages/botocore/hooks.py&quot;, line 228, in emit
      return self._emit(event_name, kwargs)
    File &quot;/home/miguel/python3/lib/python3.6/site-packages/botocore/hooks.py&quot;, line 211, in _emit
      response = handler(**kwargs)
    File &quot;/home/miguel/python3/lib/python3.6/site-packages/botocore/signers.py&quot;, line 90, in handler
      return self.sign(operation_name, request)
    File &quot;/home/miguel/python3/lib/python3.6/site-packages/botocore/signers.py&quot;, line 152, in sign
      auth = self.get_auth_instance(**kwargs)
    File &quot;/home/miguel/python3/lib/python3.6/site-packages/botocore/signers.py&quot;, line 232, in get_auth_instance
      frozen_credentials = self._credentials.get_frozen_credentials()
    File &quot;/home/miguel/python3/lib/python3.6/site-packages/botocore/credentials.py&quot;, line 605, in get_frozen_credentials
      self._refresh()
    File &quot;/home/miguel/python3/lib/python3.6/site-packages/botocore/credentials.py&quot;, line 500, in _refresh
      self._protected_refresh(is_mandatory=is_mandatory_refresh)
    File &quot;/home/miguel/python3/lib/python3.6/site-packages/botocore/credentials.py&quot;, line 531, in _protected_refresh
      self._set_from_data(metadata)
    File &quot;/home/miguel/python3/lib/python3.6/site-packages/botocore/credentials.py&quot;, line 560, in _set_from_data
      error_msg=message % ', '.join(missing_keys),
  botocore.exceptions.CredentialRetrievalError: Error when retrieving credentials from iam-role: Credential refresh failed, response did not contain: access_key, secret_key, token, expiry_time
  
  </code></pre>