# Create a destination for GCP + GCS + Databricks or Snowflake

To populate your <u>**GCP + Google Cloud Storage**</u> (<u>**GCS**</u>) repository with healthcare data from an EHR system via Redox (and then to optionally feed that data into <u>**Databricks**</u> or <u>**Snowflake**</u> for analytics), you must configure a specific <u>Redox cloud destination</u>. A Redox <u>destination</u> represents where a message is delivered (e.g., like the address in the “To” line of an email header). [Learn more about connecting Redox to your cloud repository](/basics/connecting-to-the-cloud-with-redox).

You'll need to perform some steps in your cloud product(s) and some in Redox. You can perform Redox setup in our dashboard or with the Redox Platform API. 

## Prerequisites

- Establish a connection with your preferred EHR system. [Learn how to request a connection](/how-to-use-redox/manage-your-redox-setup/request-a-connection-or-subscription).
- Decide which combination of <u>**cloud products**</u> to use. Redox currently supports any of these combinations with your GCP cloud repository: 
  1. <u>**Google Cloud Platform**</u> (<u>**GCP**</u>) + <u>**Google Cloud Storage**</u> (<u>**GCS**</u>)
  2. <u>**GCP**</u> + <u>**GCS**</u> + <u>**Databricks**</u>
  3. <u>**GCP**</u> + <u>**GCS**</u> + <u>**Snowflake**</u>
- Complete your GCP (and any other cloud product) configuration _before_ creating your Redox destination. Save any downloads with secret values, since you’ll need to enter some of these details into the Redox dashboard.
- Grant access to Redox from GCP (and any other cloud product) to authorize Redox to push data to your cloud repository.

## Configure in GCP

1. Navigate to the GCP dashboard and log in. 
2. [Create a GCS bucket](https://cloud.google.com/storage/docs/creating-buckets). 
3. [Create a service account](https://cloud.google.com/iam/docs/service-accounts-create) in your GCP project.
4. Grant the service account read/write access to the GCS bucket.
5. Create a new key for your service account. 
6. Download the new key file. _Save this file, since you’ll need it for Redox setup later._ 

## Create a cloud destination in Redox

Next, create a <u>cloud destination</u> in your Redox organization. When the EHR system sends healthcare data to Redox, we push it on to your configured GCP + GCS cloud destination.

### In the dashboard

1. For the select destination step, [follow the instructions for creating a cloud destination](https://docs.redoxengine.com/permalink/5FMTxkOE7yrDCBgiqfV3Z7/#create-a-destination). 
   - From the <u>Product type</u> field, select **Databricks** or **Snowflake** if you’re using one of those cloud products with GCS. Your GCS settings will be applied with the additional cloud product. 
Select **Cloud Storage** if you’re not using either Databricks or Snowflake. 
2. For the configure destination step, populate these fields. 
   - <u>Bucket name</u>: Enter the **GCS bucket** **name**. 
_Locate this value in the GCP dashboard._ 


> **Bucket naming requirements**
>
> We validate that the bucket name meets Google's naming requirements. [Review bucket naming requirements](https://cloud.google.com/storage/docs/buckets#naming).


   - <u>Object filename prefix</u>: Enter any **prefix** you want prepended to new files when they’re created in the GCS bucket. Add `/` to put the files in a subdirectory. For example, `redox/` puts all the files in the `redox` directory.
3. Click the **Next** button. 
4. For the auth credential step, either a drop-down list of existing auth credentials displays or a new auth credential form opens. [Learn how to create an auth credential](https://docs.redoxengine.com/permalink/zls5RsKlytlTl9kebQnLz/#o-auth-2-0-2-legged-with-jwt-for-gcp) for OAuth 2.0 2-legged with JWT for GCP.  


> **Existing or new auth credential**
>
> Your existing auth credentials will only display if they’re supported for the cloud product type you selected. If you don’t have any supported auth credentials for the cloud type in the current Redox environment, you’ll have to create a new auth credential.




> **Different Client ID**
>
> Keep in mind that the client ID value is a little different for GCP destinations. Make sure to set the client ID value to the client email (e.g., `"``clientId": "<client_email>"`).


5. For the verify step, [follow the instructions for verifying a destination](https://docs.redoxengine.com/permalink/5FMTxkOE7yrDCBgiqfV3Z7/#step-4-verify-destination). 

### With the Redox Platform API

1. [Review the Create auth credential endpoint](https://docs.redoxengine.com/permalink/dd0240f7-18d1-593d-87a7-d81bf86f543c-create-auth-cred).
2. In your terminal, prepare the `/v1/authcredentials` request.
3. Specify these values in the request. 
   - Locate the **`private_key_id`**, **`private_key_id`**, and **`client_email`** values in the downloaded key file from GCP. 
   - Make sure the auth credential’s environment ID matches the environment ID of the destination you intend to link it to.
   - Use the values we provide in the example for `authStrategy`, `grantType`, `algorithm`, `url`, and `scopes`. These are fixed values. 


**Example: Create auth credential for GCP + GCS + Databricks or Snowflake**

```json
curl 'https://api.redoxengine.com/platform/v1/authcredentials' \
--request POST \
--header 'Authorization: Bearer $API_TOKEN' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '{
    "organization": "<Redox_organization_id>"
    "name": "<human_readable_name_for_auth_credential>"
    "environmentId": "<Redox_environment_ID>"
    "authStrategy": "OAuth_2.0_JWT_GCP"
    "grantType": "client_credentials"
    "url": "https://oauth2.googleapis.com/token"
    "algorithm": "RS256"
    "clientId": "<client_email>"
    "scopes": "https://www.googleapis.com/auth/devstorage.read_write"
    "keyId": "<keyId_from_GCP>"
    "privateKey": "<privateKey_from_GCP>"
  }

```


4. You should get a successful `200` response and a `payload` populated with the details of the new auth credential. 
5. [Review the Create destination endpoint](https://docs.redoxengine.com/permalink/96830826-bf9c-5d5a-878c-b5b3f1402f30-create-destination).
6. In your terminal, prepare the `/v1/environments/{environmentId}/destinations` request with these values:
   - Set `authCredential` to the auth credential ID from the response you received in step #4.  
   - Populate `cloudProviderSettings` with the settings below.
     - The `fileNamePrefix` is optional. If specified, the filename format will be the prefix you define appended by the log ID. If not specified, the filename will simply be the log ID.
     - Enter the `productId` based on your specific setup: 
       - <u>**GCS only**</u>: `gcs`.
       - <u>**GCS + Databricks**</u>: `databricks`
       - <u>**GCS + Snowflake**</u>: `snowflake`


**Example: Values for GCP + Databricks or Snowflake cloudProviderSettings**

```json
{
  "cloudProviderSettings": {
    "typeId": "gcp",
    "productId": "<databricks_or_snowflake_or_gcs>", 
    "settings": {
      "bucketName": "<bucket_name_from_GCS>", 
      "fileNamePrefix": "<optional_prefix>",
        //You can append `/` after the prefix name to indicate a directory path"
     }
  }
}
```


7. You should get a successful `200` response with a `payload` populated with the details of the new GCP cloud destination. Specifically, the `verified` status of the destination should be set to `true`. 
8. Your new destination will now be able to receive messages. These messages get stored in your GCS bucket, which can then be picked up by Databricks or Snowflake for further processing.
