Connecting to Azure Cosmos DB using a connection string is a straightforward process that requires a few key pieces of information.
To get started, you'll need to gather your Azure Cosmos DB account's endpoint and primary key, which can be found in the Azure portal under the "Keys" section of your account settings.
First, navigate to the Azure portal and sign in with your Azure account credentials.
From there, select your Azure Cosmos DB account and click on the "Keys" tab to access your account's endpoint and primary key.
Connecting to Azure Cosmos DB
Connecting to Azure Cosmos DB is relatively straightforward. To get started, you'll need to select your Azure Cosmos DB resource and choose the API type you're working with, such as Core API, Cassandra API, or MongoDB API.
For Core API, you'll need to provide connection details, including the URI, Primary Key, and database name. The URI is the API endpoint URI, the Primary Key is a unique secret key granting access to the Cosmos DB resource, and the database name is the database to be documented.
For Cassandra API, you'll need to provide the Host, Port, User, Password, and Keyspace. The Host is the API endpoint URI, the Port is the Cassandra API port (default is 10350), the User is the Cassandra API username, the Password is either the Primary Password or Secondary Password, and the Keyspace is the keyspace to be documented.
You can find these connection details in the Azure portal by selecting your Azure Cosmos DB resource, opening the Connection String tab under Settings, and selecting the Read-only keys tab.
Here's a list of connection details for each API type:
Azure Cosmos DB SQL
To connect to Azure Cosmos DB using the SQL API, you'll need to provide a few key pieces of information. The first is the URI, which is the API endpoint URI for your Cosmos DB resource.
The primary key is another important piece of the puzzle - it's a unique secret key that grants access to your Cosmos DB resource. Make sure to keep it safe and secure, as it's essential for authenticating your connection.
You'll also need to specify the database you want to connect to. Clicking the [...] button will expand a list of available databases for you to choose from.
Azure Cosmos DB - Cassandra API
To connect to Azure Cosmos DB's Cassandra API, you'll need to find your Azure Cosmos DB resource and select your Cassandra API account. Then, navigate to the left-hand side menu and open the Connection String tab under Settings.
The Connection String tab will have two tabs: Read-write keys and Read-only keys. For documentation purposes, you can use the Read-only keys.
To get the necessary connection details, you'll need to provide the following information:
- Host - API endpoint URI,
- Port - Cassandra API port, which is 10350 by default,
- User - Cassandra API username,
- Password - either Primary Password or Secondary Password,
- Keyspace - the keyspace to be documented, which can be expanded by clicking the [...] button.
Azure Cosmos DB MongoDB API
To connect to Azure Cosmos DB using the MongoDB API, you need to select the connection type, either Connection string or Values. We recommend choosing Connection string as it provides the full connection string available in the Azure Portal.
You'll need to provide connection details, including the connection string and database to be documented. To find the connection string, navigate to the Azure Cosmos DB resource, select your Azure Cosmos DB MongoDB API account, and then open the Connection String tab under Settings.
The Connection String tab has two sub-tabs: Read-write keys and Read-only keys. For documenting purposes, Read-only keys are sufficient. You can use either the Primary Connection String or Secondary Connection String as the connection string in Dataedo.
Security and Identity
To connect to Azure Cosmos DB using a connection string, you need to consider security and identity. You can specify a managed identity in a connection string to operate under a specific role.
A system-assigned managed identity or a user-assigned managed identity can be used on a data source connection string. You can create a data source connection to CosmosDB in the Azure portal, specifying either a system or user-assigned managed identity.
The managed identity connection string format is the same for the REST API, .NET SDK, and the Azure portal. This means you can use the same connection string format regardless of the API or SDK you're using.
Connecting with a user-assigned managed identity requires two changes to the data source definition.
Sources
- https://dataedo.com/docs/connecting-to-azure-cosmos-db
- https://www.etlbox.net/docs/nosql-connectors/cosmos-db/
- https://docs.sisense.com/win/SisenseWin/connecting-to-cosmosdb.htm
- https://microsoftlearning.github.io/dp-420-cosmos-db-dev/instructions/05-sdk-offline.html
- https://learn.microsoft.com/en-us/azure/search/search-howto-managed-identities-cosmos-db
Featured Images: pexels.com