Skip to content

Openflow - SFTP

Goal of this tutorial is to load data from SFTP into Snowflake stage via openflow.

Video

Requirements

  • You can NOT be on a trial account. (Link)
  • Snowflake account has to be in an AWS region.(Link)

Download

Snowflake

Lets start the snowflake setup by going into a workspace worksheet (1) and creating the nesseray objects for openflow and the connector.

  1. Worksheet
If you don't have a database, schema, or warehouse yet.
-- Create a database to store our schemas.
create database if not exists raw;

-- Create the schema. The schema stores all objects.
create schema if not exists raw.sftp;
create schema if not exists raw.network;

/*
    Warehouses are synonymous with the idea of compute
    resources in other systems. We will use this
    warehouse to query our integration and to load data.
*/
create warehouse if not exists openflow 
    warehouse_size = xsmall
    auto_suspend = 30
    initially_suspended = true;

Only required if your hosting openflow in Snowflake (SPCS)

Lets create the network rule and external access that will allow openflow/snowflake to talk with our SFTP.

-- Create network rule for our SFTP.
create or replace network rule sftp_network_rule
    mode = egress
    type = host_port
    value_list = (
        '<SFTP URL>:22'
    );

-- Create one external access integration with all network rules.
create or replace external access integration openflow_external_access
    allowed_network_rules = (sftp_network_rule)
    enabled = true;
-- create network rule for google apis
create or replace network rule sftp_network_rule
    mode = egress
    type = host_port
    value_list = (
        'danielwilczaksftp.blob.core.windows.net:22'
    );

-- Create one external access integration with all network rules.
create or replace external access integration openflow_external_access
    allowed_network_rules = (sftp_network_rule)
    enabled = true;

Integration OPENFLOW_EXTERNAL_ACCESS successfully created.

Now we will need a stage to store the files we pull from our SFTP.

-- Stage to store files in.
create stage files directory = ( enable = true );

Stage area FILES successfully created.

Openflow

Next we'll head into openflow to setup our runtime and add the connector. UPDATE

If you get the error 'Invalid consent request' or 'TOTP Invalid'

You will have to change your default role to a role that is not an admin role. Example default would be public. UPDATE

Click "Launch openflow". UPDATE

Add the connector

We'll create a new runtime. UPDATE

We'll select our deployment, give the runtime a name, select our snowflake role and if deployed in Snowflake our external access intergration. UPDATE

Now we'll wait 5-10 minutes for our runtime to become usable. UPDATE

If you get the error 'Invalid consent request' or 'TOTP Invalid'

You will have to change your default role to a role that is not an admin role. Example default would be public. UPDATE

Once the runtime is "Active" we can click to go into it. UPDATE

Next we'll drag a process group to the canvas. UPDATE

We'll click "Browse" button and upload our connector we downloaded at the start of the tutorial. UPDATE

We'll click "Add". UPDATE

Paramaters

Now we'll see the connector on the canvas, we'll right click and select "paramaters". UPDATE

We'll click cancel. UPDATE

Next we'll edit each paramater group. These are just the basics. UPDATE

SFTP Credentials

We'll enter in our SFTP URL, username and upload our key. If you want to use a password you can modify this in the process I just haven't added here. I will show this in the video. UPDATE

Now for the key file you'll have to click "reference assests" and then the upload button. UPDATE

Click upload again. UPDATE

Once uploaded click cancel. UPDATE

Now select the file and click okay. UPDATE

Once everything has been edited, click apply. UPDATE

Snowflake Credentials

Now we will do the same for our Snowflake credentials. If your hosting Openflow in AWS make sure your authentication strategy is "KEY_PAIR". UPDATE

(Optional) Snowflake for AWS

Only required if your hosting openflow in AWS

UPDATE

Running the connector

Next we'll head back to the canvas. UPDATE

Right click the connector and add "Enable all controller services". UPDATE

Now lets go into the connector to look at what we can change and also run it one step at a time. Double click the connector. UPDATE

Right click the first step "ListSFTP", and click configure. This step will allow us to look into how the files are selected before grabbing them. In our case we are just going to pull all files in all folders. UPDATE

Once we are happy with the configurations we can go back and right click again and click "Run Once". This will allow us to list the files to grab in the next step. UPDATE

Now that it has successfully run, we can right click the success box and look at queue of files to grab. UPDATE

We can see all the files to pull in on the next step. UPDATE

Now we can run the next step once again. UPDATE

This time if we look at the queue it will allow us to download the file if we wanted to validate it. UPDATE

Now we can run the final step that will put it into our stage. UPDATE

Now that we have a successful run of the final step we can go back into Snowflake UI and see our file in the stage once we click refresh. UPDATE