问题
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