title: Lambda function times out when connecting to a boto3 client
body: <h2>The Problem</h2>
  <p>I am trying to set up a lambda function to do some tasks on ec2. I keep running into a timeout error. A minimal example reproducing the problem is as follows:</p>
  <pre><code>import boto3
  
  REGION = &quot;us-west-2&quot;
  ec2 = boto3.client('ec2', region_name=REGION)
  
  
  def main(event, context):
      
      region = ec2.describe_regions()
      return region
  
  </code></pre>
  <p>The lambda function is called <code>lambda_function</code> and the handler is <code>lambda_function.main</code>. The runtime environment is Python 3.6, Python 3.7 or Python 3.8 (and I have the same error in each).</p>
  <p>This function returns the following error:</p>
  <pre><code>Response:
  {
    &quot;errorMessage&quot;: &quot;2020-11-27T05:26:27.739Z xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Task timed out after 20.02 seconds&quot;
  }
  
  Request ID:
  &quot;xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&quot;
  
  Function logs:
  START RequestId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Version: $LATEST
  END RequestId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
  REPORT RequestId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx  Duration: 20020.38 ms   Billed Duration: 20000 ms   Memory Size: 128 MB Max Memory Used: 81 MB  Init Duration: 343.37 ms    
  2020-11-27T05:26:27.739Z xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx Task timed out after 20.02 seconds
  </code></pre>
  <h2>Permissions and Policies</h2>
  <p>The lambda function is running with a role with the following permissions:</p>
  <ul>
  <li>AmazonEC2FullAccess</li>
  <li>AWSLambdaFullAccess</li>
  <li>CloudWatchLogsFullAccess</li>
  </ul>
  <p>The user that is setting up the lambda function has the following permissions:</p>
  <ul>
  <li>AmazonRDSFullAccess</li>
  <li>AmazonEC2FullAccess</li>
  <li>SecretsManagerReadWrite</li>
  <li>AWSLambdaFullAccess</li>
  <li>AmazonS3FullAccess</li>
  <li>AmazonDynamoDBFullAccess</li>
  <li>AWSLambda_FullAccess</li>
  <li>EC2InstanceConnect</li>
  </ul>
  <p>If I run the commands from my terminal, using the same credentials that this IAM user has, I get the expected output.</p>
  <pre><code>$ aws ec2 describe-regions
  {
      &quot;Regions&quot;: [
          {
              &quot;Endpoint&quot;: &quot;ec2.eu-north-1.amazonaws.com&quot;,
              &quot;RegionName&quot;: &quot;eu-north-1&quot;,
              &quot;OptInStatus&quot;: &quot;opt-in-not-required&quot;
          },
  
      ...]
  }
  </code></pre>
  <h2>Network and security groups</h2>
  <p>The lambda is assigned to the default VPC of the IAM user. The security groups attached to this lambda function are the default security group for this VPC, and some additional security groups allowing some additional access.</p>
  <p>What is causing the timeout? How do I fix this?</p>