

# Connecting to Azure Cosmos DB in AWS Glue Studio
Connecting to Azure Cosmos DB

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

**Topics**
+ [

# Creating a Azure Cosmos DB connection
](creating-azurecosmos-connection.md)
+ [

# Creating a Azure Cosmos DB source node
](creating-azurecosmos-source-node.md)
+ [

# Creating a Azure Cosmos DB target node
](creating-azurecosmos-target-node.md)
+ [

## Advanced options
](#creating-azurecosmos-connection-advanced-options)

# Creating a Azure Cosmos DB connection


**Prerequisites**:
+ In Azure, you will need to identify or generate an Azure Cosmos DB Key for use by AWS Glue, `cosmosKey`. For more information, see [Secure access to data in Azure Cosmos DB](https://learn.microsoft.com/en-us/azure/cosmos-db/secure-access-to-data?tabs=using-primary-key) in the Azure documentation.

**To configure a connection to Azure Cosmos DB:**

1. In AWS Secrets Manager, create a secret using your Azure Cosmos DB Key. 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 `spark.cosmos.accountKey` with the value *cosmosKey*.

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 Cosmos DB.
   + When selecting an **AWS Secret**, provide *secretName*.

# Creating a Azure Cosmos DB source node


## Prerequisites needed

+ A AWS Glue Azure Cosmos DB connection, configured with an AWS Secrets Manager secret, as described in the previous section, [Creating a Azure Cosmos DB connection](creating-azurecosmos-connection.md).
+ Appropriate permissions on your job to read the secret used by the connection.
+ A Azure Cosmos DB for NoSQL container you would like to read from. You will need identification information for the container.

  An Azure Cosmos for NoSQL container is identified by its database and container. You must provide the database, *cosmosDBName*, and container, *cosmosContainerName*, names when connecting to the Azure Cosmos for NoSQL API.

## Adding a Azure Cosmos DB data source


**To add a **Data source – Azure Cosmos DB** node:**

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

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

1. Choose **Cosmos DB Database Name** – provide the name of the database you want to read from, *cosmosDBName*.

1. Choose **Azure Cosmos DB Container** – provide the name of the container you want to read from, *cosmosContainerName*.

1. Optionally, choose **Azure Cosmos DB Custom Query** – provide a SQL SELECT query to retrieve specific information from Azure Cosmos DB.

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

# Creating a Azure Cosmos DB target node


## Prerequisites needed

+ A AWS Glue Azure Cosmos DB connection, configured with an AWS Secrets Manager secret, as described in the previous section, [Creating a Azure Cosmos DB connection](creating-azurecosmos-connection.md).
+ Appropriate permissions on your job to read the secret used by the connection.
+ A Azure Cosmos DB table you would like to write to. You will need identification information for the container. **You must create the container before calling the connection method.**

  An Azure Cosmos for NoSQL container is identified by its database and container. You must provide the database, *cosmosDBName*, and container, *cosmosContainerName*, names when connecting to the Azure Cosmos for NoSQL API.

## Adding a Azure Cosmos DB data target


**To add a **Data target – Azure Cosmos DB** node:**

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

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

1. Choose **Cosmos DB Database Name** – provide the name of the database you want to read from, *cosmosDBName*.

1. Choose **Azure Cosmos DB Container** – provide the name of the container you want to read from, *cosmosContainerName*.

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

## Advanced options


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

See [Azure Cosmos DB connections](aws-glue-programming-etl-connect-azurecosmos-home.md). 