list_datasets()方法在AWS Lambda中不执行任何操作 [英] list_datasets() method does nothing in AWS Lambda
问题描述
我正在尝试从AWS lambda内的BigQuery获取数据集列表.但是,在执行client.list_datasets()
方法时,它不执行任何操作,并且lambda超时.
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.
我的代码如下:
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>
但是,没有打印dataset.__dict__
的第二张照片.或者,不执行HTTPIterator
对象的循环.
But, the second print for dataset.__dict__
is not being printed. Or, looping over the HTTPIterator
object is not performed.
顺便说一句,该代码在本地计算机上运行良好.
推荐答案
我在lambda函数中使用的AWS VPC导致了此问题. VPC阻止了对外部API(在我的情况下为BigQuery API)的请求.
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).
配置VPC子网和NAT网关以将lambda功能公开给Internet(0.0.0.0/0)解决了该问题.
Configuring the VPC subnet and NAT Gateway to expose lambda function to the internet (0.0.0.0/0) solved the issue.
这篇关于list_datasets()方法在AWS Lambda中不执行任何操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!