-
On the Taskbar, click the Microsoft Edge icon.
-
In the open browser window, navigate to the Azure Portal (https://portal.azure.com).
-
If prompted, authenticate with the user account account that has the owner role in the Azure subscription you will be using in this lab.
-
In the upper left corner of the Azure portal, click Create a resource.
-
At the top of the New blade, in the Search the Marketplace text box, type Cosmos DB and press Enter.
-
On the Everything blade, in the search results, click Azure Cosmos DB.
-
On the Azure Cosmos DB blade, click the Create button.
-
On the new Azure Cosmos DB blade, perform the following tasks:
-
Leave the Subscription drop-down list entry set to its default value.
-
Resource group: ensure that the Create new option is selected and then, in the text box, type AADesignLab0701-RG.
-
In the Account Name text box, type cosmosdb(YourName).
-
In the API drop-down list, select the Core (SQL) option.
-
In the Location drop-down list, select (Asia Pacific) Southeast Asia.
-
Leave all remaining settings with their default values.
-
Click the Review + create button and then click the Create button.
-
-
Wait for the provisioning to complete before you proceed to the next step.
Note: The deployment could take up to 10 to 15 minutes.
-
Navigate to the blade of the newly created Cosmos DB account and click Keys.
-
On the Cosmos DB account Keys blade, note the value of the PRIMARY CONNECTION STRING. You will need it in the third exercise of this lab.
Note: Example primary connection string: AccountEndpoint=https://cosmosdbstv.documents.azure.com:443/;AccountKey=n98TNtaQJsSKHqJT6sUcGQ5RJ8seYzLlrDPqxhMxafz2SoC24ETyvFQiHyA7R7vdGGGLPW7nxziHpLAEfvzTQA==;
-
At the top of the portal, click the Cloud Shell icon to open a new shell instance.
Note: The Cloud Shell icon is a symbol that is constructed of the combination of the greater than and underscore characters.
-
If this is your first time opening the Cloud Shell using your subscription, you will see a wizard to configure Cloud Shell for first-time usage. When prompted, in the Welcome to Azure Cloud Shell pane, click Bash (Linux).
Note: If you do not see the configuration options for Cloud Shell, this is most likely because you are using an existing subscription with this course's labs.
-
Wait for the Cloud Shell to finish its setup procedures before you proceed to the next task.
-
At the Cloud Shell command prompt, type in the following command and press Enter to create a variable which value designates the name of the resource group that contains the Azure Cosmos DB account you deployed earlier in this task:
RESOURCE_GROUP='AADesignLab0701-RG' -
At the Cloud Shell command prompt, type in the following command and press Enter to create a variable which value designates the name of the CosmosDB account you created earlier in this task:
COSMOSDB_NAME=$(az cosmosdb list --resource-group $RESOURCE_GROUP --query "[0].name" --output tsv) -
At the Cloud Shell command prompt, type in the following command and press Enter to create a variable which value designates the primary key of the CosmosDB account you created earlier in this task:
PRIMARY_KEY=$(az cosmosdb keys list --resource-group $RESOURCE_GROUP --name $COSMOSDB_NAME --output json | jq -r '.primaryMasterKey') -
At the Cloud Shell command prompt, type in the following command and press Enter to create a variable which value designates the URI of the CosmosDB account you created earlier in this task:
URI="https://$COSMOSDB_NAME.documents.azure.com:443/" -
At the Cloud Shell command prompt, type in the following command and press Enter to create a new CosmosDB database named FinancialClubDatabase:
az cosmosdb database create --url-connection $URI --key $PRIMARY_KEY --db-name 'FinancialClubDatabase'
-
At the Cloud Shell command prompt, type in the following command and press Enter to create a fixed collection named MemberCollection in the newly created database:
az cosmosdb collection create --url-connection $URI --key $PRIMARY_KEY --db-name 'FinancialClubDatabase' --collection-name 'MemberCollection' --throughput 400
-
At the Cloud Shell command prompt, type in the following command and press Enter to display the value of the PRIMARY_KEY variable:
echo $PRIMARY_KEY
-
At the Cloud Shell command prompt, type in the following command and press Enter to display the value of the URI variable:
echo $URI
Note: Take a note of these values - you will need them in the third exercise of this lab.
-
On the left side of the Azure Cosmos DB account blade, click Data Explorer.
-
In the Data Explorer pane, if necessary, refresh the pane and then click the MemberCollection child node of the FinancialClubDatabase node.
-
Click the New SQL Query button at the top of the Data Explorer pane.
-
In the Query 1 tab that opened, view the default query:
SELECT * FROM c
-
Click the Execute Query button at the top of the query editor and verify that the query does not return any results.
-
In the left pane of the Data Explorer, expand the MemberCollection node.
-
Click the Items child node within the MemberCollection node.
-
In the new Items tab that opened, click the New Item button at the top of the tab.
-
In the Items tab, replace the existing document with the following document:
{ "firstName": "Pennington", "lastName": "Oneal", "age": 26, "salary": 90000.00, "company": "Veraq", "isVested": false } -
Click the Save button at the top of the Items tab (you might need to first click the ellipsis toolbar button).
-
In the Items tab, click the New Item button at the top of the tab.
-
In the Items tab, replace the existing document with the following document:
{ "firstName": "Suzanne", "lastName": "Oneal", "company": "Veraq" } -
Click the Save button at the top of the Items tab.
-
Switch back to the Query 1 tab, re-run the default query
SELECT * FROM cby clicking the Execute Query button at the top of the query editor, and review the results. -
In the query editor, replace the default query with the following query:
SELECT c.id, c.firstName, c.lastName, c.isVested, c.company FROM c WHERE IS_DEFINED(c.isVested)
-
Click the Execute Query button at the top of the query editor and review the results.
-
In the query editor, replace the existing query with the following query:
SELECT c.id, c.firstName, c.lastName, c.age FROM c WHERE c.age > 20
-
Click the Execute Query button at the top of the query editor and review the results.
-
In the query editor, replace the existing query with the following query:
SELECT VALUE c.id FROM c
-
Click the Execute Query button at the top of the query editor and review the results.
-
In the query editor, replace the existing query with the following query:
SELECT VALUE { "badgeNumber": SUBSTRING(c.id, 0, 8), "company": c.company, "fullName": CONCAT(c.firstName, " ", c.lastName) } FROM c
-
Click the Execute Query button at the top of the query editor and review the results.
Review: In this exercise, you created a new Cosmos DB account, database, and collection, added sample items to the collection, and run sample queries targeting these items.
-
In the upper left corner of the Azure portal, click Create a resource.
-
At the top of the New blade, in the Search the Marketplace text box, type Template Deployment and press Enter.
-
On the Everything blade, in the search results, click Template Deployment.
-
On the Template deployment blade, click the Create button.
-
On the Custom deployment blade, click the Build your own template in the editor link.
-
On the Edit template blade, click the Load file link.
-
In the Open file dialog that appears, navigate to the \allfiles\AZ-301T02\Module_02\LabFiles\Starter\ folder.
-
Select the api.json file.
-
Click the Open button.
-
Back on the Edit template blade, click the Save button to persist the template.
-
Back on the Custom deployment blade, perform the following tasks:
-
Leave the Subscription drop-down list entry set to its default value.
-
In the Resource group section, select the Use existing option and then, in the drop-down list, select AADesignLab0701-RG.
-
Click the Create button.
-
-
Wait for the deployment to complete before you proceed to the next task.
Note: Deployment from source control can take up to 10 minutes.
-
In the hub menu in the Azure portal, click Resource groups.
-
On the Resource groups blade, click AADesignLab0701-RG.
-
On the AADesignLab0701-RG blade, click the entry representing the newly created App Service API app.
-
On the API app blade, under Settings, click Configuration.
-
On the Application Settings blade, scroll down to the Application settings section and perform the following tasks:
-
Set the value of the CosmosDB:AuthorizationKey setting to the value of the PRIMARY KEY setting of the Cosmos DB account you created earlier in this lab.
-
Update the value of the CosmosDB:EndpointUrl setting to the value of the URI setting of the Cosmos DB instance you created earlier in this lab.
-
Click the Save button at the top of the pane (if prompted, click Continue).
-
-
On the left-side of the API app blade, click Overview.
-
Click the Restart button at the top of the blade and, when prompted to confirm, click Yes.
-
Click the Browse button at the top of the blade. This will open a new browser tab displaying the Swagger UI homepage.
Note: If you click the Browse button before the API app has fully restarted, you may not be able to follow the remaining steps in this task. If this happens, refresh your browser until the API app is running again.
-
On the Swagger UI homepage, click GET/Documents.
-
Click the Try it out! button.
-
Review the results of the request (the results should include 2 items).
-
Back on the Swagger UI homepage, click POST/Populate.
-
In the Parameters section, in the Value field for the options parameter, paste in the following JSON content:
{ "quantity": 50 } -
In the Response Messages section, click the Try it out! button.
-
Review the results of the request (the results should include 50 items).
-
Back on the Swagger UI homepage, click GET/Documents.
-
Locate the Response Messages section. Click the Try it out! button.
-
Review the results of the request (the results should include 52 items).
-
Close the new browser tab and return to the browser tab displaying the Azure portal.
Review: In this exercise, you created a new API App that uses the .NET Core DocumentDB SDK to connect to Azure Cosmos DB collection and manage its documents.
-
In the upper left corner of the Azure portal, click Create a resource.
-
At the top of the New blade, in the Search the Marketplace text box, type Search and press Enter.
-
On the Showing All Results blade, in the search results, click Azure Cognitive Search.
-
On the Azure Cognitive Search blade, click the Create button.
-
On the New Search Service blade, perform the following tasks:
-
Leave the Subscription drop-down list entry set to its default value.
-
In the Resource group section, select the Use existing option and then, in the drop-down list, select AADesignLab0701-RG.
-
In the URL text box, enter a globally unique name. Record its value. You will use it later in this lab.
-
In the Location drop-down list, select the Azure region matching or near the location where you deployed Cosmos DB resource earlier in this labb
-
Click Change Pricing Tier.
-
On the Select Pricing Tier blade, click Free and then click the Select button.
-
Click the Review + create button, review the settings then click Create.
-
-
Wait for the provisioning to complete before you proceed to the next step.
-
In the hub menu in the Azure portal, click Resource groups.
-
On the Resource groups blade, click AADesignLab0701-RG.
-
On the AADesignLab0701-RG blade, click the entry representing the newly created Azure Search instance.
-
On the Search service blade, click Keys.
-
In the Keys pane, record the value of QUERY KEY. You will use it later in this lab.
Note: The query key is located below the primary and secondary keys, and does not have a name by default.
-
In the hub menu in the Azure portal, click Resource groups.
-
On the Resource groups blade, click AADesignLab0701-RG.
-
On the AADesignLab0701-RG blade, click the entry representing the Azure Search instance you created earlier in this lab.
-
On the Overview blade of Azure Search service, click Import data.
-
On the Connect to your data tab, perform the following tasks:
-
In the Data Source drop down list, select Cosmos DB.
-
In the Name text box, type cosmosdata.
-
In the Cosmos DB account text box, type the Cosmos DB account connection string you identfied earlier in this lab.
-
In the Database drop-down list, select the FinancialClubDatabase entry.
-
in the Collection drop-down list, select the MemberCollection entry.
-
In the Query field, enter the following SQL query:
SELECT c.id, c.firstName, c.lastName, c.age, c.salary, c.company, c.isVested, c._ts FROM c WHERE c._ts >= @HighWaterMark ORDER BY c._ts
-
Ensure that the Query results ordered by _ts checkbox is selected.
-
Click the Next: Add cognitive skills (optional) button.
-
-
On the Cognitive Search blade, click the Skip to: Customize target index button.
-
On the Customize target index blade, perform the following tasks:
-
In the Index name text box, type memberindex.
-
In the Key drop-down list, ensure that the id entry is selected.
-
For the id field in the table, ensure that the RETRIEVABLE, FILTERABLE, and SORTABLE checkboxes are selected.
-
For the firstName field in the table, ensure that the RETRIEVABLE, SORTABLE, and SEARCHABLE options are selected.
-
For the lastName field in the table, ensure that the RETRIEVABLE, SORTABLE, and SEARCHABLE checkboxes are selected.
-
For the age field in the table, ensure that the RETRIEVABLE, FILTERABLE, SORTABLE, and FACETABLE checkboxes are selected.
-
For the salary field in the table, ensure that the RETRIEVABLE, FILTERABLE, SORTABLE, and FACETABLE checkboxes are selected.
-
For the company field in the table, ensure that the RETRIEVABLE, FACETABLE, and SEARCHABLE checkboxes are selected.
-
For the isVested field in the table, ensure that the RETRIEVABLE, FILTERABLE, SORTABLE, FACETABLE checkboxes are selected.
-
Click the Next: Create an indexer button.
-
-
On the Create an Indexer blade, perform the following tasks:
-
In the Name text box, type cosmosmemberindexer.
-
In the Schedule section, select the Custom option.
-
In the Interval (minutes) text box, type 5.
-
In the Start time (UTC) field, specify the current date and accept the default value of the time entry.
-
Ensure that the Track deletions checkbox is clear and click the Submit button.
-
-
In the hub menu in the Azure portal, click Resource groups.
-
On the Resource groups blade, click AADesignLab0701-RG.
-
On the AADesignLab0701-RG blade, click the entry representing the App Service API app you created earlier in this lab.
-
On the API app blade, click Configuration.
-
On the Application settings blade, scroll down to the Application settings section and perform the following tasks:
-
Set the value of the Search:AccountName setting to the name of the Azure Search instance you created earlier in this lab.
-
Set the value of the Search:QueryKey setting to the value of the QUERY KEY of the Azure Search instance you created earlier in this lab.
-
Set the value of the Search:IndexId setting to the value memberindex.
-
Click the Save button at the top of the blade (if prompted, click Continue).
-
-
On the API app blade, click Overview.
-
Click the Restart button at the top of the blade and, when prompted to confirm, click Yes.
-
Click the Browse button at the top of the blade. This will open a new browser tab displaying the Swagger UI homepage.
Note: If you click the Browse button before the API app has fully restarted, you may not be able to follow the remaining steps in this task. If this happens, refresh your browser until the API app is running again.
-
On the Swagger UI homepage, click Cosmos DB API v.1.0.0 at the top of the page and select the Cosmos DB API v.2.0.0 option from the drop-down list.
-
Click GET/Documents/search.
-
In the Parameters section, in the Value text box of the query parameter, type the following text:
Oneal -
In the Response Messages section, click the Try it out! button.
-
Review the results of the request (the results should include 2 items).
-
In the Parameters section, in the Value text box of the query parameter, type the following text:
penn* -
In the Response Messages section, click the Try it out! button.
-
Review the results of the request (the results should include 1 item).
-
Close the new browser tab and return to the browser tab displaying the Azure portal.
Review: In this exercise, you created an Azure Search instance that uses an indexer to index the documents in Azure Cosmos DB.
-
At the Cloud Shell command prompt, type in the following command and press Enter to delete the resource groups you created in this lab
az group list --query "[?starts_with(name,'AADesignLab0701')]".name --output tsv | xargs -L1 bash -c 'az group delete --name $0 --no-wait --yes'
Review: In this exercise, you removed the resources used in this lab.