

# Connecting to Azure SQL in AWS Glue Studio
<a name="connecting-to-data-azuresql"></a>

 AWS Glue provides built-in support for Azure SQL. AWS Glue Studio provides a visual interface to connect to Azure SQL, author data integration jobs, and run them on the AWS Glue Studio serverless Spark runtime. 

**Topics**
+ [Creating a Azure SQL connection](creating-azuresql-connection.md)
+ [Creating a Azure SQL source node](creating-azuresql-source-node.md)
+ [Creating a Azure SQL target node](creating-azuresql-target-node.md)
+ [Advanced options](#creating-azuresql-connection-advanced-options)

# Creating a Azure SQL connection
<a name="creating-azuresql-connection"></a>

To connect to Azure SQL from AWS Glue, you will need to create and store your Azure SQL credentials in a AWS Secrets Manager secret, then associate that secret with a Azure SQL AWS Glue connection.

**To configure a connection to Azure SQL:**

1. In AWS Secrets Manager, create a secret using your Azure SQL credentials. To create a secret in Secrets Manager, follow the tutorial available in [ Create an AWS Secrets Manager secret ](https://docs.aws.amazon.com//secretsmanager/latest/userguide/create_secret.html) in the AWS Secrets Manager documentation. After creating the secret, keep the Secret name, *secretName* for the next step. 
   + When selecting **Key/value pairs**, create a pair for the key `user` with the value *azuresqlUsername*.
   + When selecting **Key/value pairs**, create a pair for the key `password` with the value *azuresqlPassword*.

1. In the AWS Glue console, create a connection by following the steps in [Adding an AWS Glue connection](console-connections.md). After creating the connection, keep the connection name, *connectionName*, for future use in AWS Glue. 
   + When selecting a **Connection type**, select Azure SQL.
   + When providing **Azure SQL URL**, provide a JDBC endpoint URL.

      The URL must be in the following format: `jdbc:sqlserver://databaseServerName:databasePort;databaseName=azuresqlDBname;`.

     AWS Glue requires the following URL properties: 
     + `databaseName` – A default database in Azure SQL to connect to.

     For more information about JDBC URLs for Azure SQL Managed Instances, see the [Microsoft documentation](https://learn.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url?view=azuresqldb-mi-current).
   + When selecting an **AWS Secret**, provide *secretName*.

# Creating a Azure SQL source node
<a name="creating-azuresql-source-node"></a>

## Prerequisites needed
<a name="creating-azuresql-source-node-prerequisites"></a>
+ A AWS Glue Azure SQL connection, configured with an AWS Secrets Manager secret, as described in the previous section, [Creating a Azure SQL connection](creating-azuresql-connection.md).
+ Appropriate permissions on your job to read the secret used by the connection.
+ A Azure SQL table you would like to read from, *tableName*.

  An Azure SQL table is identified by its database, schema and table name. You must provide the database name and table name when connecting to Azure SQL. You also must provide the schema if it is not the default, "public". Database is provided through a URL property in *connectionName* , schema and table name through the `dbtable`.

## Adding a Azure SQL data source
<a name="creating-azuresql-source-node-add"></a>

**To add a **Data source – Azure SQL** node:**

1.  Choose the connection for your Azure SQL data source. Since you have created it, it should be available in the dropdown. If you need to create a connection, choose **Create Azure SQL connection**. For more information see the previous section, [Creating a Azure SQL connection](creating-azuresql-connection.md). 

    Once you have chosen a connection, you can view the connection properties by clicking **View properties**. 

1.  Choose a **Azure SQL Source** option: 
   +  **Choose a single table** – access all data from a single table. 
   +  **Enter custom query ** – access a dataset from multiple tables based on your custom query. 

1.  If you chose a single table, enter *tableName*. 

    If you chose **Enter custom query**, enter a TransactSQL SELECT query. 

1.  In **Custom Azure SQL properties**, enter parameters and values as needed. 

# Creating a Azure SQL target node
<a name="creating-azuresql-target-node"></a>

## Prerequisites needed
<a name="creating-azuresql-target-node-prerequisites"></a>
+ A AWS Glue Azure SQL connection, configured with an AWS Secrets Manager secret, as described in the previous section, [Creating a Azure SQL connection](creating-azuresql-connection.md).
+ Appropriate permissions on your job to read the secret used by the connection.
+ A Azure SQL table you would like to write to, *tableName*.

  An Azure SQL table is identified by its database, schema and table name. You must provide the database name and table name when connecting to Azure SQL. You also must provide the schema if it is not the default, "public". Database is provided through a URL property in *connectionName* , schema and table name through the `dbtable`.

## Adding a Azure SQL data target
<a name="creating-azuresql-target-node-add"></a>

**To add a **Data target – Azure SQL** node:**

1.  Choose the connection for your Azure SQL data source. Since you have created it, it should be available in the dropdown. If you need to create a connection, choose **Create Azure SQL connection**. For more information see the previous section, [Creating a Azure SQL connection](creating-azuresql-connection.md). 

    Once you have chosen a connection, you can view the connection properties by clicking **View properties**. 

1. Configure **Table name** by providing *tableName*.

1.  In **Custom Azure SQL properties**, enter parameters and values as needed. 

## Advanced options
<a name="creating-azuresql-connection-advanced-options"></a>

You can provide advanced options when creating a Azure SQL node. These options are the same as those available when programming AWS Glue for Spark scripts.

See [Azure SQL connections](aws-glue-programming-etl-connect-azuresql-home.md). 