list_datasets() method does nothing in AWS Lambda

两盒软妹~` 提交于 2019-12-23 04:56:23

问题


I am trying to get the list of datasets from BigQuery inside the AWS lambda. But, while executing the client.list_datasets() method it does nothing and lambda is timed out.

My code is as follows:

from google.cloud.bigquery import Client
from google.oauth2.service_account import Credentials

credentials = Credentials.from_service_account_info(
            service_account_dict)

client = Client(
            project=service_account_dict.get("project_id"),
            credentials=credentials
        )

datasets = client.list_datasets()
print(datasets)

for dataset in datasets:
    print("dataset info", dataset.__dict__)

The output of first print statement is:

<google.api_core.page_iterator.HTTPIterator object at 0x7fbae4975550>

But, the second print for dataset.__dict__ is not being printed. Or, looping over the HTTPIterator object is not performed.

BTW, the code works perfectly fine in local machine.


回答1:


The AWS VPC that I used in lambda function was causing this issue. The VPC blocked requests to the external API (in my case BigQuery API).

Configuring the VPC subnet and NAT Gateway to expose lambda function to the internet (0.0.0.0/0) solved the issue.



来源:https://stackoverflow.com/questions/55827466/list-datasets-method-does-nothing-in-aws-lambda

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!