@@ -129,6 +129,7 @@ def __init__(
129
129
bq_connection_client ,
130
130
bq_connection_id ,
131
131
cloud_resource_manager_client ,
132
+ cloud_function_service_account ,
132
133
):
133
134
self ._gcp_project_id = gcp_project_id
134
135
self ._cloud_function_region = cloud_function_region
@@ -140,6 +141,7 @@ def __init__(
140
141
self ._bq_connection_manager = clients .BqConnectionManager (
141
142
bq_connection_client , cloud_resource_manager_client
142
143
)
144
+ self ._cloud_function_service_account = cloud_function_service_account
143
145
144
146
def create_bq_remote_function (
145
147
self , input_args , input_types , output_type , endpoint , bq_function_name
@@ -384,6 +386,9 @@ def create_cloud_function(self, def_, cf_name, package_requirements=None):
384
386
function .service_config = functions_v2 .ServiceConfig ()
385
387
function .service_config .available_memory = "1024M"
386
388
function .service_config .timeout_seconds = 600
389
+ function .service_config .service_account_email = (
390
+ self ._cloud_function_service_account
391
+ )
387
392
create_function_request .function = function
388
393
389
394
# Create the cloud function and wait for it to be ready to use
@@ -591,6 +596,7 @@ def remote_function(
591
596
reuse : bool = True ,
592
597
name : Optional [str ] = None ,
593
598
packages : Optional [Sequence [str ]] = None ,
599
+ cloud_function_service_account : Optional [str ] = None ,
594
600
):
595
601
"""Decorator to turn a user defined function into a BigQuery remote function.
596
602
@@ -646,12 +652,12 @@ def remote_function(
646
652
Client to use for BigQuery operations. If this param is not provided
647
653
then bigquery client from the session would be used.
648
654
bigquery_connection_client (google.cloud.bigquery_connection_v1.ConnectionServiceClient, Optional):
649
- Client to use for cloud functions operations. If this param is not
650
- provided then functions client from the session would be used.
651
- cloud_functions_client (google.cloud.functions_v2.FunctionServiceClient, Optional):
652
655
Client to use for BigQuery connection operations. If this param is
653
656
not provided then bigquery connection client from the session would
654
657
be used.
658
+ cloud_functions_client (google.cloud.functions_v2.FunctionServiceClient, Optional):
659
+ Client to use for cloud functions operations. If this param is not
660
+ provided then the functions client from the session would be used.
655
661
resource_manager_client (google.cloud.resourcemanager_v3.ProjectsClient, Optional):
656
662
Client to use for cloud resource management operations, e.g. for
657
663
getting and setting IAM roles on cloud resources. If this param is
@@ -686,7 +692,13 @@ def remote_function(
686
692
Explicit name of the external package dependencies. Each dependency
687
693
is added to the `requirements.txt` as is, and can be of the form
688
694
supported in https://pip.pypa.io/en/stable/reference/requirements-file-format/.
689
-
695
+ cloud_function_service_account (str, Optional):
696
+ Service account to use for the cloud functions. If not provided then
697
+ the default service account would be used. See
698
+ https://cloud.google.com/functions/docs/securing/function-identity
699
+ for more details. Please make sure the service account has the
700
+ necessary IAM permissions configured as described in
701
+ https://cloud.google.com/functions/docs/reference/iam/roles#additional-configuration.
690
702
"""
691
703
import bigframes .pandas as bpd
692
704
@@ -787,6 +799,7 @@ def wrapper(f):
787
799
bigquery_connection_client ,
788
800
bq_connection_id ,
789
801
resource_manager_client ,
802
+ cloud_function_service_account ,
790
803
)
791
804
792
805
rf_name , cf_name = remote_function_client .provision_bq_remote_function (
0 commit comments