Today, I was deploying a python service that uses pygsheets to save data on Google Sheets.
The script was tested on local and EC2 instance and works like charm, but when I decided to package it and deploy on Lambda function an error came out.
{ "errorMessage": "[Errno 97] Address family not supported by protocol", "errorType": "OSError", "stackTrace": [ " File \"/var/task/app.py\", line 28, in lambda_handler\n sh = gc.open_by_key(\"*******************--**P-dE\")\n", " File \"/var/task/pygsheets/client.py\", line 159, in open_by_key\n response = self.sheet.get(key,\n", " File \"/var/task/pygsheets/sheet.py\", line 164, in get\n return self._execute_requests(self.service.spreadsheets().get(spreadsheetId=spreadsheet_id, **kwargs))\n", ] }
After a lot of searching trying to investigate what is Address family not supported by protocol means I figured out the issue while trying to call an API with IPv6 and it’s not supported by default if you are running Lambda function in default VPC, but in my case I was running it inside a VPC created for production but the attached subnets to Lambda function wasn’t support IPv6 routing.
If your function is associated with a subnets that includes IPv6 CIDR then your Lambda to access external resources without any issues.
Any external API call that goes outside your VPC will fail with IPv6 CIDR and the solution is to create a dedicated subnets just for your Lambda functions which supports IPv6.
Solution Step by Step
- Enable IPv6 support to your VPC
Login to AWS console > VPC > Select your VPC > From Action dropdown select Edit CIDRs
![](https://hossamelshahawi.com/wp-content/uploads/2021/10/image-4-1024x270.png)
![](https://hossamelshahawi.com/wp-content/uploads/2021/10/image-6-1024x206.png)
![](https://hossamelshahawi.com/wp-content/uploads/2021/10/image-7.png)
When it down you will see that it’s associated.
![](https://hossamelshahawi.com/wp-content/uploads/2021/10/image-8-1024x138.png)
2. Create 2 Subnets with IPv6 CIDR
Now go to subnets section in VPC and click on Create subnet
![](https://hossamelshahawi.com/wp-content/uploads/2021/10/image-11.png)
Select your vpc and other filed like IPv4 CIDR and another section came as we enabled IPv6 to our VPC
![](https://hossamelshahawi.com/wp-content/uploads/2021/10/image-10.png)
Note it’s highly recommended to associated at least 2 subnets for Lambda to run your functions in high availability.
3. Associated the 2 new subnets to Lambda function
Now you have to navigate to your lambda function and select Configuration tab
![](https://hossamelshahawi.com/wp-content/uploads/2021/10/image-12.png)
And attache the 2 new subnets to your function.
I assume you already have an associated VPC and subnets to your function so, you have to replace the old subnets with new created.
That’s it, after saving changes you can test and will find the error disappeared.
Thank you, It was really helpful!
We are still facing same issue we have tried with go and python but not able to communicate to third party IPv6 only endpoint from application hosted in aws lambda