# Snowflake Autoscaler

Espresso AI uses ML models to optimize Snowflake workloads in real time.

## How it works

1. Espresso trains custom models on your Snowflake metadata. This usually takes between 15 minutes and 48 hours, depending on the number of queries and warehouses in your account.
2. Once the models are trained, you receive a savings estimate.
3. You also get access to the Espresso dashboard, where you can turn optimization on across your account or for specific warehouses.

## Create a Snowflake service user and role

Run the following commands in Snowflake to set up access for Espresso. We only access metadata. You can find the list of metadata we read on [Snowflake Metadata](https://docs.espresso.ai/snowflake-optimizer/snowflake-metadata).

```sql
-- Create the Espresso AI user with our public key
CREATE USER espresso_ai_user
  TYPE=SERVICE
  RSA_PUBLIC_KEY='MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA6GfMQyT/1ZQS1wwTeF3Q
lbHJyBSuIio+UlnZixffvo9UwP/ild6R4AqOEma39Ty1zuLibbyNSgjTYqNXv7QNiEgR50SvEo27N6EJ
I1EOnJPREzi060E64eXMrc1mwPrERxtEtNXgJBUs3Y2aKsGKoo900jkjK08CrMNBM1uzyXhLBS5a4sND
Slef4JjyZCBl4iHTqmeqD0xZJCC2/Rlr40UGPq+Ae/zXyyDyQkWE69ytZQRjPXvv8b2x6C9JtKYqtklJ
ljzFy74eQZV4m9hxtH+r1Z32zyhjNGhYaRF/0yD3gNWg135cexfyd5M8PKPt1Km4VAV6oPr8QYEfvS50
0QIDAQAB';

CREATE ROLE IF NOT EXISTS ESPRESSO_AI_USER
  COMMENT = 'Used by Espresso AI';

GRANT ROLE ESPRESSO_AI_USER TO USER ESPRESSO_AI_USER;

-- Allow Espresso AI to query Snowflake metadata
GRANT IMPORTED PRIVILEGES ON DATABASE SNOWFLAKE
  TO ROLE ESPRESSO_AI_USER;

-- Allow Espresso AI to securely export data
ALTER USER ESPRESSO_AI_USER
  SET PREVENT_UNLOAD_TO_INLINE_URL = false;

-- Allow Espresso AI to monitor warehouses
GRANT MONITOR USAGE ON ACCOUNT
  TO ROLE ESPRESSO_AI_USER;

-- Give Espresso AI the ability to modify warehouses
GRANT MANAGE WAREHOUSES ON ACCOUNT
  TO ROLE ESPRESSO_AI_USER;

-- Set up a warehouse for Espresso AI queries to run on
CREATE WAREHOUSE IF NOT EXISTS
  ESPRESSO_AI_WH WAREHOUSE_SIZE = XSMALL
  AUTO_SUSPEND = 60 INITIALLY_SUSPENDED = TRUE
  COMMENT = 'Used by Espresso AI';

GRANT MONITOR, OPERATE, USAGE, MODIFY
  ON WAREHOUSE ESPRESSO_AI_WH
  TO ROLE ESPRESSO_AI_USER;
```

## Share your account details

After you run the Snowflake commands, fill out the form below with your account information.

Your account hostname is the URL you use to sign in to Snowflake, for example `https://<account>.snowflakecomputing.com/`.

{% @espresso-web-form/web-form submitUrl="<https://hooks.zapier.com/hooks/catch/25164061/u7rro69/>" submitMethod="POST" submitFormat="urlencoded" submitButtonLabel="Get started" successMessage="Thanks. You should receive a savings estimate and dashboard access shortly." errorMessage="Something went wrong while submitting the form." fieldsJson="\[
{
"name": "Email",
"label": "Email",
"type": "email",
"required": true,
"placeholder": "Email\*"
},
{
"name": "Snowflake-Account-Hostname",
"label": "Snowflake account hostname",
"type": "text",
"required": true,
"placeholder": "Snowflake Account Hostname\*"
},
{
"name": "Role-name",
"label": "Role name",
"type": "text",
"required": true,
"placeholder": "Role name (e.g. ESPRESSO\_USER)\*"
},
{
"name": "utm\_source",
"type": "hidden",
"defaultValue": ""
},
{
"name": "utm\_medium",
"type": "hidden",
"defaultValue": ""
},
{
"name": "utm\_campaign",
"type": "hidden",
"defaultValue": ""
},
{
"name": "utm\_term",
"type": "hidden",
"defaultValue": ""
},
{
"name": "utm\_content",
"type": "hidden",
"defaultValue": ""
},
{
"name": "gclid",
"type": "hidden",
"defaultValue": ""
},
{
"name": "li\_fat\_id",
"type": "hidden",
"defaultValue": ""
}
]" %}

## Optional: IP allowlist

If you use Snowflake network policies, allow these IPs:

* `18.233.13.51`
* `34.195.242.31`
* `34.231.116.52`
* `34.231.212.71`
* `34.234.123.175`
* `35.169.148.94`
* `52.87.110.223`
* `54.161.160.239`

## Questions?

[Book a call](https://espresso.ai/demo) if you have questions or want an NDA in place.
