Create an AWS connection

Add credentials to connect BigQuery to AWS.

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

Java

Before trying this sample, follow theJava setup instructions in theBigQuery quickstart using client libraries. For more information, see theBigQueryJava API reference documentation.

To authenticate to BigQuery, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.

importcom.google.cloud.bigquery.connection.v1.AwsAccessRole;importcom.google.cloud.bigquery.connection.v1.AwsProperties;importcom.google.cloud.bigquery.connection.v1.Connection;importcom.google.cloud.bigquery.connection.v1.CreateConnectionRequest;importcom.google.cloud.bigquery.connection.v1.LocationName;importcom.google.cloud.bigqueryconnection.v1.ConnectionServiceClient;importjava.io.IOException;// Sample to create aws connectionpublicclassCreateAwsConnection{publicstaticvoidmain(String[]args)throwsIOException{// TODO(developer): Replace these variables before running the sample.StringprojectId="MY_PROJECT_ID";// Example of location: aws-us-east-1Stringlocation="MY_LOCATION";StringconnectionId="MY_CONNECTION_ID";// Example of role id: arn:aws:iam::accountId:role/myroleStringiamRoleId="MY_AWS_ROLE_ID";AwsAccessRolerole=AwsAccessRole.newBuilder().setIamRoleId(iamRoleId).build();AwsPropertiesawsProperties=AwsProperties.newBuilder().setAccessRole(role).build();Connectionconnection=Connection.newBuilder().setAws(awsProperties).build();createAwsConnection(projectId,location,connectionId,connection);}staticvoidcreateAwsConnection(StringprojectId,Stringlocation,StringconnectionId,Connectionconnection)throwsIOException{try(ConnectionServiceClientclient=ConnectionServiceClient.create()){LocationNameparent=LocationName.of(projectId,location);CreateConnectionRequestrequest=CreateConnectionRequest.newBuilder().setParent(parent.toString()).setConnection(connection).setConnectionId(connectionId).build();Connectionresponse=client.createConnection(request);AwsAccessRolerole=response.getAws().getAccessRole();System.out.println("Aws connection created successfully : Aws userId :"+role.getIamRoleId()+" Aws externalId :"+role.getIdentity());}}}

What's next

To search and filter code samples for other Google Cloud products, see theGoogle Cloud sample browser.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.