Connecting BigQuery to Amazon S3 has never been easier. You create an IAM policy and role in AWS, create the connection in BigQuery, then add a trust policy to the role using the identity BigQuery gives you. After that you can query the files in SQL.
This guide covers the cross-cloud connection described in Google’s cross-cloud connections documentation. For the background, see our overview of what cross-cloud connections are.
Prerequisites
You’ll need the following in place:
- BigQuery permissions: The roles/bigquery.admin role on the Google Cloud project, or a custom role with equivalent permissions.
- AWS permissions: A role that can create IAM policies and roles in the AWS account that owns the bucket.
- The BigQuery Connection API: Enabled on the project (bigqueryconnection.googleapis.com).
- A BigQuery location: A standard location, such as us-east4. Do not use a BigQuery Omni location. Pick the closest one to your S3 region. For example, AWS us-east-1 maps to us-east4 and AWS eu-west-2 maps to europe-west2. Use the placeholders below throughout: BUCKET_NAME, AWS_ACCOUNT_ID, POLICY_NAME, ROLE_NAME, PROJECT_ID, LOCATION and CONNECTION_ID.
Create an AWS IAM Policy
The policy decides what BigQuery can do in the bucket and should start with read-only access. Google recommends a few hardening steps on the bucket as well such as deny HTTP access, block public access, use S3 server-side encryption, and turn on CloudTrail with S3 data events. In the AWS IAM console, go to Policies, choose Create policy, switch to the JSON tab and paste the following. Replace BUCKET_NAME with your bucket.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::BUCKET_NAME"
]
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::BUCKET_NAME",
"arn:aws:s3:::BUCKET_NAME/*"
]
}
]
}
Name the policy, for example bq_omni_read_only, and choose Create policy. The policy ARN has the format arn:aws:iam::AWS_ACCOUNT_ID:policy/POLICY_NAME. If you also want to export from BigQuery to S3, add s3:PutObject. Google recommends a separate connection and role for exports.
Create an AWS IAM Role
The role is what BigQuery assumes. You create it now with a placeholder and fix the trust policy in Step 4. Within the AWS CLI:
aws iam create-role \
--role-name bigquery-omni-connection \
--max-session-duration 43200 \
--assume-role-policy-document '{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "accounts.google.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"accounts.google.com:sub": "00000"
}
}
}
]
}'
Then attach the policy from the previous step:
aws iam attach-role-policy \
--role-name bigquery-omni-connection \
--policy-arn arn:aws:iam::AWS_ACCOUNT_ID:policy/POLICY_NAME
In the console, the same role is created with Web Identity as the trusted entity type, Google as the identity provider and 00000 as the audience. The maximum session duration must be 12 hours (43200 seconds). Google explains that a query can run for up to six hours, so 12 hours leaves room for one retry. The role ARN has the format arn:aws:iam::AWS_ACCOUNT_ID:role/ROLE_NAME and is needed in the next step.
Create the Connection in BigQuery
Console
- Open the BigQuery page and expand your project in Explorer.
- Expand Connections and choose Create connection.
- Set Connection type to BigLake on AWS (via BigQuery Omni).
- Enter a Connection ID.
- Set Region to your standard BigQuery location.
- Enter the AWS role ID: arn:aws:iam::AWS_ACCOUNT_ID:role/ROLE_NAME.
- Optionally tick Enable cross-cloud caching. It is off by default.
- Choose Create connection, then Go to connection.
- In the Connection info pane, copy the BigQuery Google identity.
bq
bq mk --connection \
--connection_type='AWS' \
--location=LOCATION \
--project_id=PROJECT_ID \
--properties='{"accessRole":{"iamRoleId":"arn:aws:iam::AWS_ACCOUNT_ID:role/ROLE_NAME"},"crossCloudCacheOptions":{"enabled":false}}' \
CONNECTION_ID
Then read the identity back:
bq show --connection \
--location=LOCATION \
PROJECT_ID.LOCATION.CONNECTION_ID
Copy the identity value from the output. Set the cache option to true if you want caching on.
Add the Trust Policy to the Role
Now replace the placeholder 00000 with the BigQuery Google identity from the above step. In the AWS CLI:
aws iam update-assume-role-policy \
--role-name bigquery-omni-connection \
--policy-document '{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "accounts.google.com"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"accounts.google.com:sub": "IDENTITY_ID"
}
}
}
]
}'
In the console, open IAM > Roles, select the role, confirm the maximum session duration is 12 hours, then edit the trust relationship and paste the same JSON. AWS can take a few minutes to apply the change. If the connection returns an error straight away, wait and retry. If your AWS account has a custom identity provider for accounts.google.com, add the identity as an audience on that provider instead. In the console that is IAM > Identity Providers, select the provider, then Add Audience.
Query the Data
Create a dataset in the same BigQuery location, then an external table that uses the connection. This example is adapted from Google’s own documentation.
CREATE SCHEMA `my-project.aws_raw_data`
OPTIONS (
location = 'us-east4');
CREATE EXTERNAL TABLE `my-project.aws_raw_data.sales_parquet`
WITH CONNECTION `us-east4.my-aws-connection`
OPTIONS (
format = 'PARQUET',
uris = ['s3://my-data-bucket/sales/year=2025/*']);
Query it as normal:
SELECT *
FROM `my-project.aws_raw_data.sales_parquet`
LIMIT 10;
To federate a whole AWS Glue database instead, use an external schema. Replace the region, account ID and database name with your own:
CREATE EXTERNAL SCHEMA `my-project.aws_glue_data`
WITH CONNECTION `us-east4.my-aws-connection`
OPTIONS (
location = 'us-east4',
external_source = 'aws-glue://arn:aws:glue:us-east-1:123456789012:database/test_database');
You can find out more about AWS Glue here.
Share the Connection
In the Google Cloud console, open the connection under Connections, choose Share, and add the people or groups who need access. Give them roles/bigquery.connectionUser to query through it. Only give roles/bigquery.connectionAdmin to people who manage it.
Common Troubleshooting
- Not authorised to assume the role: Check that the iamRoleId matches the role ARN in
bq show, that the trust policy contains the identity, and wait a few minutes after any change. - Session duration too short: Set the role’s maximum session duration to 12 hours.
- Custom identity provider: Add the identity as an audience on the provider.
- Access denied reading from S3: Check that the path in uris exists. The policy needs s3:ListBucket on the bucket and s3:GetObject on the objects. If the bucket uses SSE-KMS encryption, the role also needs kms:Decrypt on the key.
- Not found: Check the bucket name and path in uris for spelling.
Newsletter
Occasional notes on data, tracking & AI-readiness
No spam, no growth-hacking. Just an email when there's something worth reading.