<pre><code>You need to create a NAT Gateway in either one of your Public subnets 'subnet-0a41b43c04095c248' and 'subnet-00303000' of the VPC. Please follow the documentation[1] to get the detailed steps of creating a NAT Gateway.

Edit the route tables of the private subnets which are associated with your Lambda function, to allow the traffic to the destination 0.0.0.0/0 with the target set to the NAT Gateway, that you created in the public subnet.
</code></pre>
<p>Ref:
<a href="https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html#nat-gateway-creating" rel="nofollow noreferrer">https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html#nat-gateway-creating</a></p>

CC BY-SA 4.0
2023-07-29T01:04:29.393Z
2023-07-29T01:04:29.393Z
Vinoth Chitrarasu
<p>I am getting connection timeout error with VPC enabled but working fine without enabled VPC.</p>
<pre><code>{
  &quot;errorMessage&quot;: &quot;HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-base-cased/resolve/main/tokenizer_config.json (Caused by ConnectTimeoutError(&lt;urllib3.connection.HTTPSConnection object at 0x7fd7f0a07040&gt;, 'Connection to huggingface.co timed out. (connect timeout=30)'))&quot;,
  &quot;errorType&quot;: &quot;ConnectTimeout&quot;,
  &quot;requestId&quot;: &quot;&quot;,
  &quot;stackTrace&quot;: [
    &quot;  File \&quot;/var/lang/lib/python3.10/importlib/__init__.py\&quot;, line 126, in import_module\n    return _bootstrap._gcd_import(name[level:], package, level)\n&quot;,
    &quot;  File \&quot;&lt;frozen importlib._bootstrap&gt;\&quot;, line 1050, in _gcd_import\n&quot;,
    &quot;  File \&quot;&lt;frozen importlib._bootstrap&gt;\&quot;, line 1027, in _find_and_load\n&quot;,
    &quot;  File \&quot;&lt;frozen importlib._bootstrap&gt;\&quot;, line 1006, in _find_and_load_unlocked\n&quot;,
    &quot;  File \&quot;&lt;frozen importlib._bootstrap&gt;\&quot;, line 688, in _load_unlocked\n&quot;,
    &quot;  File \&quot;&lt;frozen importlib._bootstrap_external&gt;\&quot;, line 883, in exec_module\n&quot;,
    &quot;  File \&quot;&lt;frozen importlib._bootstrap&gt;\&quot;, line 241, in _call_with_frames_removed\n&quot;,
    &quot;  File \&quot;/var/task/spellCorrection_rest_app.py\&quot;, line 4, in &lt;module&gt;\n    response = requests.head(url, timeout=30)  # Increase the timeout value as needed\n&quot;,
    &quot;  File \&quot;/var/task/requests/api.py\&quot;, line 100, in head\n    return request(\&quot;head\&quot;, url, **kwargs)\n&quot;,
    &quot;  File \&quot;/var/task/requests/api.py\&quot;, line 59, in request\n    return session.request(method=method, url=url, **kwargs)\n&quot;,
    &quot;  File \&quot;/var/task/requests/sessions.py\&quot;, line 589, in request\n    resp = self.send(prep, **send_kwargs)\n&quot;,
    &quot;  File \&quot;/var/task/requests/sessions.py\&quot;, line 703, in send\n    r = adapter.send(request, **kwargs)\n&quot;,
    &quot;  File \&quot;/var/task/requests/adapters.py\&quot;, line 507, in send\n    raise ConnectTimeout(e, request=request)\n&quot;
  ]
}
</code></pre>

<aws-lambda><aws-vpc>
AWS lambda failed after enabled VPC
Vinoth Chitrarasu
# AWS lambda failed after enabled VPC

(Asked by: username_0 on 2023-07-27)

I am getting connection timeout error with VPC enabled but working fine without enabled VPC.
{
  "errorMessage": "HTTPSConnectionPool(host='huggingface.co', port=443): Max retries exceeded with url: /bert-base-cased/resolve/main/tokenizer_config.json (Caused by ConnectTimeoutError(, 'Connection to huggingface.co timed out. (connect timeout=30)'))",
  "errorType": "ConnectTimeout",
  "requestId": "",
  "stackTrace": [
    "  File \"/var/lang/lib/python3.10/importlib/__init__.py\", line 126, in import_module\n    return _bootstrap._gcd_import(name[level:], package, level)\n",
    "  File \"\", line 1050, in _gcd_import\n",
    "  File \"\", line 1027, in _find_and_load\n",
    "  File \"\", line 1006, in _find_and_load_unlocked\n",
    "  File \"\", line 688, in _load_unlocked\n",
    "  File \"\", line 883, in exec_module\n",
    "  File \"\", line 241, in _call_with_frames_removed\n",
    "  File \"/var/task/spellCorrection_rest_app.py\", line 4, in \n    response = requests.head(url, timeout=30)  # Increase the timeout value as needed\n",
    "  File \"/var/task/requests/api.py\", line 100, in head\n    return request(\"head\", url, **kwargs)\n",
    "  File \"/var/task/requests/api.py\", line 59, in request\n    return session.request(method=method, url=url, **kwargs)\n",
    "  File \"/var/task/requests/sessions.py\", line 589, in request\n    resp = self.send(prep, **send_kwargs)\n",
    "  File \"/var/task/requests/sessions.py\", line 703, in send\n    r = adapter.send(request, **kwargs)\n",
    "  File \"/var/task/requests/adapters.py\", line 507, in send\n    raise ConnectTimeout(e, request=request)\n"
  ]
}

**Tags:** aws-lambda, aws-vpc


---

## 1 answers

### Answer by username_0 on 2023-07-29. Score: 0

You need to create a NAT Gateway in either one of your Public subnets 'subnet-0a41b43c04095c248' and 'subnet-00303000' of the VPC. Please follow the documentation[1] to get the detailed steps of creating a NAT Gateway.

Edit the route tables of the private subnets which are associated with your Lambda function, to allow the traffic to the destination 0.0.0.0/0 with the target set to the NAT Gateway, that you created in the public subnet.

Ref:
https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html#nat-gateway-creating


---

