Regenerates an access key for the specified Azure Cosmos DB database account.
POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.DocumentDB/databaseAccounts/{accountName}/regenerateKey?api-version=2023-11-15
URI Parameters
Name |
In |
Required |
Type |
Description |
accountName
|
path |
True
|
string
|
Cosmos DB database account name.
Regex pattern: ^[a-z0-9]+(-[a-z0-9]+)*
|
resourceGroupName
|
path |
True
|
string
|
The name of the resource group. The name is case insensitive.
|
subscriptionId
|
path |
True
|
string
|
The ID of the target subscription.
|
api-version
|
query |
True
|
string
|
The API version to use for this operation.
|
Request Body
Name |
Required |
Type |
Description |
keyKind
|
True
|
KeyKind
|
The access key to regenerate.
|
Responses
Name |
Type |
Description |
200 OK
|
|
OK
|
202 Accepted
|
|
Accepted. The regenerate key operation will complete asynchronously.
Headers
- azure-AsyncOperation: string
- location: string
|
Security
azure_auth
Azure Active Directory OAuth2 Flow
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize
Scopes
Name |
Description |
user_impersonation
|
Impersonate your user account
|
Examples
CosmosDBDatabaseAccountRegenerateKey
Sample Request
POST https://management.azure.com/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.DocumentDB/databaseAccounts/ddb1/regenerateKey?api-version=2023-11-15
{
"keyKind": "primary"
}
import com.azure.resourcemanager.cosmos.models.DatabaseAccountRegenerateKeyParameters;
import com.azure.resourcemanager.cosmos.models.KeyKind;
/**
* Samples for DatabaseAccounts RegenerateKey.
*/
public final class Main {
/*
* x-ms-original-file: specification/cosmos-db/resource-manager/Microsoft.DocumentDB/stable/2023-11-15/examples/
* CosmosDBDatabaseAccountRegenerateKey.json
*/
/**
* Sample code: CosmosDBDatabaseAccountRegenerateKey.
*
* @param azure The entry point for accessing resource management APIs in Azure.
*/
public static void cosmosDBDatabaseAccountRegenerateKey(com.azure.resourcemanager.AzureResourceManager azure) {
azure.cosmosDBAccounts().manager().serviceClient().getDatabaseAccounts().regenerateKey("rg1", "ddb1",
new DatabaseAccountRegenerateKeyParameters().withKeyKind(KeyKind.PRIMARY),
com.azure.core.util.Context.NONE);
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
from azure.identity import DefaultAzureCredential
from azure.mgmt.cosmosdb import CosmosDBManagementClient
"""
# PREREQUISITES
pip install azure-identity
pip install azure-mgmt-cosmosdb
# USAGE
python cosmos_db_database_account_regenerate_key.py
Before run the sample, please set the values of the client ID, tenant ID and client secret
of the AAD application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID,
AZURE_CLIENT_SECRET. For more info about how to get the value, please see:
https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal
"""
def main():
client = CosmosDBManagementClient(
credential=DefaultAzureCredential(),
subscription_id="subid",
)
client.database_accounts.begin_regenerate_key(
resource_group_name="rg1",
account_name="ddb1",
key_to_regenerate={"keyKind": "primary"},
).result()
# x-ms-original-file: specification/cosmos-db/resource-manager/Microsoft.DocumentDB/stable/2023-11-15/examples/CosmosDBDatabaseAccountRegenerateKey.json
if __name__ == "__main__":
main()
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
package armcosmos_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/cosmos/armcosmos/v2"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/41e4538ed7bb3ceac3c1322c9455a0812ed110ac/specification/cosmos-db/resource-manager/Microsoft.DocumentDB/stable/2023-11-15/examples/CosmosDBDatabaseAccountRegenerateKey.json
func ExampleDatabaseAccountsClient_BeginRegenerateKey() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armcosmos.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
poller, err := clientFactory.NewDatabaseAccountsClient().BeginRegenerateKey(ctx, "rg1", "ddb1", armcosmos.DatabaseAccountRegenerateKeyParameters{
KeyKind: to.Ptr(armcosmos.KeyKindPrimary),
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
_, err = poller.PollUntilDone(ctx, nil)
if err != nil {
log.Fatalf("failed to pull the result: %v", err)
}
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { CosmosDBManagementClient } = require("@azure/arm-cosmosdb");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to Regenerates an access key for the specified Azure Cosmos DB database account.
*
* @summary Regenerates an access key for the specified Azure Cosmos DB database account.
* x-ms-original-file: specification/cosmos-db/resource-manager/Microsoft.DocumentDB/stable/2023-11-15/examples/CosmosDBDatabaseAccountRegenerateKey.json
*/
async function cosmosDbDatabaseAccountRegenerateKey() {
const subscriptionId = process.env["COSMOSDB_SUBSCRIPTION_ID"] || "subid";
const resourceGroupName = process.env["COSMOSDB_RESOURCE_GROUP"] || "rg1";
const accountName = "ddb1";
const keyToRegenerate = {
keyKind: "primary",
};
const credential = new DefaultAzureCredential();
const client = new CosmosDBManagementClient(credential, subscriptionId);
const result = await client.databaseAccounts.beginRegenerateKeyAndWait(
resourceGroupName,
accountName,
keyToRegenerate,
);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample Response
Location: https://centraluseuap.management.azure.com/subscriptions/d1eb41bc-1b7f-4404-bd2a-8568c222852d/providers/Microsoft.DocumentDB/locations/centraluseuap/operationsStatus/fdd04b7b-86d5-460f-b19e-386230348bcc?api-version=2023-11-15
Azure-AsyncOperation: https://centraluseuap.management.azure.com/subscriptions/d1eb41bc-1b7f-4404-bd2a-8568c222852d/providers/Microsoft.DocumentDB/locations/centraluseuap/operationsStatus/fdd04b7b-86d5-460f-b19e-386230348bcc?api-version=2023-11-15
Definitions
DatabaseAccountRegenerateKeyParameters
Parameters to regenerate the keys within the database account.
Name |
Type |
Description |
keyKind
|
KeyKind
|
The access key to regenerate.
|
KeyKind
The access key to regenerate.
Name |
Type |
Description |
primary
|
string
|
|
primaryReadonly
|
string
|
|
secondary
|
string
|
|
secondaryReadonly
|
string
|
|