Azure core tools - how to specify a different key name when fetching connection string - azure

Is there a way to tell the tool what field name in my local.settings.json file I want to update when fetching a connection string? so specifically, when I run this command:
func azure storage fetch-connection-string $STORAGE_ACCOUNT_NAME
by default, it grabs the name of my storage account (mystorage123) and appends "_STORAGE" to it. So you end up with something like this:
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "dotnet",
"mystorage123_STORAGE": "DefaultEndpointsProtocol=https;AccountName=mystorage123;AccountKey=<key>"
},
"ConnectionStrings": {}
}
I would like it just to create a json field / key that just matches the actual account name - in this case "mystorage123".
Is there a way to do this?
I know I can write powershell code to update my json file manually. But it'd be better if I can just tell the command what to call the field.
Thanks.

I would like it just to create a json field / key that just matches
the actual account name - in this case "mystorage123". Is there a way
to do this? I know I can write powershell code to update my json file
manually. But it'd be better if I can just tell the command what to
call the field.
I don’t think there is such a way. This connection string is originally been spliced.

Related

Can I pull data from an existingAzure Storage Account table using ARM Templates?

I have an existing Azure Storage Account which has a table. This table has a few details that I would be needing to use in my mainTemplate.json ARM file. Can I pull these values directly in the ARM Template.
[concat(reference(resourceId('Microsoft.Storage/storageAccounts',parameters('storageAccountName'))).primaryEndpoints.table, parameters('tableName'))]
I have been using the above statement in the outputs section and it returns me the table uri. Can I get the values inside that table by any way?
As suggested by Silent By referring this link
Try with using DeploymentScriptOutputs
The script takes one parameter, and output the parameter value. DeploymentScriptOutputs is used for storing outputs.
example
"outputs": {
"result": {
"value": "[reference('runPowerShellInlineWithOutput').outputs.text]",
"type": "string"
}
}
In the outputs section, the value line shows how to access the stored values. Write-Output is used for debugging purpose. To learn how to access the output file, see Monitor and troubleshoot deployment scripts
Thank you #silent for your suggestion

Why does my Azure Cosmos DB SQL API Container Refuse Multiple Items With Same Partition Key Value?

In Azure Cosmos DB (SQL API) I've created a container whose "partition key" is set to /part_key and I am now trying to create and edit data in Data Explorer.
I created an item that looks like this:
{
"id": "test_id",
"value": "val000",
"magicNumber": 32,
"part_key": "asdf"
}
I am now trying to create an item that looks like this:
{
"id": "frank",
"value": "val001",
"magicNumber": 33,
"part_key": "asdf"
}
Based on the documentation I believe that each item within a partition key needs a distinct id, which to me implies that multiple items can in fact share a partition key, which makes a lot of sense.
However, I get an error when I try to save this second item:
{"code":409,"body":{"code":"Conflict","message":"Entity with the specified id already exists in the system...
I see that if I change the value of part_key to something else (say asdf2), then I can save this new item.
Either my expectations about this functionality are wrong, or else I'm doing this wrong somehow. What is wrong here?
Your understanding is correct, It could happen if you are trying to instead a new document with id equal to id of the existing document. This is not allowed, so operation fails.
Before you insert the modified copy, you need to assign a new id to it. I tested the scenario and it looks fine. May be try to create a new document and check

Azure TimerTrigger Multiple instances with different configuration

Using VS Code + "Azure Function" Extension, I generated the default python 3.7 timedTrigger function with the following settings:
// functions.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "mytimer",
"type": "timerTrigger",
"direction": "in",
"schedule": "0 0 */6 * * *"
}
]
}
I have also set up two environment variables "USER" and "PASSWORD" which are set up in the Configuration of the app service.
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": ****************,
"FUNCTIONS_WORKER_RUNTIME": "python",
"USER": "********",
"PASSWORD": "*********"
}
}
Goal:
I want to run two instances of the same function, but using two different Configs, i.e. Users+Passwords.
Problem:
I believe that the Configuration/App Settings might not be sufficient for this. I can't find a way to run the function twice with multiple different parameters.
Question: What options do I have to reach my goal? One idea I had was to put the User/PW into the functions.json, but I could not figure out how to access that information from within the app function.
You have two options:
Read a custom json (not necessarily reading the value of function.json), you can add a custom json in the function app, and then read the value you want according to the hierarchy of the json file, Then use the value you read in the trigger.
Use deployment slot. (This is the official method, I think it is completely suitable for your current needs)
In this newly created slot you can use completely different environment variables in Configuration Settings.
This is the doc:
https://learn.microsoft.com/en-us/azure/azure-functions/functions-deployment-slots
I'd probably do it by having a single setting that holds a JSON array, viz
"Credentials": "[{'username':'***','password':'***'},{'username':'******','password':'******'}]"
Then, assuming you want to process them all at the same time, make a single function that parses the array and iterates over each username and password.
If you need to run them on different schedules, create a shared Python function DoTheThing(credentialIndex) that actually does the work and then multiple Azure Functions that simply call DoTheThing(0), DoTheThing(1), ...
(Security note: not immediately relevant to the problem at hand, but secrets are best kept in a secret store such as Key Vault rather than directly in the settings)
EDIT/SOLUTION:
I ended up having a the following keys in my environment variables:
"USERS": "[\"UserA\", \"UserB\"]"
"UserA_USER": "Username1"
"UserA_PW": "Password1"
"UserB_USER": "Username2"
"UserB_PW": "Password2"
Then I iterated over the USERS array and retrieved the keys for each user like so:
import os
import json
users = json.loads(os.environ["USERS"])
for u in users:
user = os.environ[u + "_USER"]
pw = os.environ[u + "_PW"]
doStuff(user, pw)

Azure : How to write path to get a file from a time series partitioned folder using the Azure logic apps

I am trying to retrieve a csv file from the Azure blob storage using the logic apps.
I set the azure storage explorer path in the parameters and in the get blob content action I am using that parameter.
In the Parameters I have set the value as:
concat('Directory1/','Year=',string(int(substring(utcNow(),0,4))),'/Month=',string(int(substring(utcnow(),5,2))),'/Day=',string(int(substring(utcnow(),8,2))),'/myfile.csv')
So during the run time this path should form as:
Directory1/Year=2019/Month=12/Day=30/myfile.csv
but during the execution action is getting failed with the following error message
{
"status": 400,
"message": "The specifed resource name contains invalid characters.\r\nclientRequestId: 1e2791be-8efd-413d-831e-7e2cd89278ba",
"error": {
"message": "The specifed resource name contains invalid characters."
},
"source": "azureblob-we.azconn-we-01.p.azurewebsites.net"
}
So my question is: How to write path to get data from the time series partitioned path.
The response of the Joy Wang was partially correct.
The Parameters in logic apps will treat values as a String only and will not be able to identify any functions such as concat().
The correct way to use the concat function is to use the expressions.
And my solution to the problem is:
concat('container1/','Directory1/','Year=',string(int(substring(utcNow(),0,4))),'/Month=',string(int(substring(utcnow(),5,2))),'/Day=',string(int(substring(utcnow(),8,2))),'/myfile.csv')
You should not use that in the parameters, when you use this line concat('Directory1/','Year=',string(int(substring(utcNow(),0,4))),'/Month=',string(int(substring(utcnow(),5,2))),'/Day=',string(int(substring(utcnow(),8,2))),'/myfile.csv') in the parameters, its type is String, it will be recognized as String by logic app, then the function will not take effect.
And you need to include the container name in the concat(), also, no need to use string(int()), because utcNow() and substring() both return the String.
To fix the issue, use the line below directly in the Blob option, my container name is container1.
concat('container1/','Directory1/','Year=',substring(utcNow(),0,4),'/Month=',substring(utcnow(),5,2),'/Day=',substring(utcnow(),8,2),'/myfile.csv')
Update:
As mentioned in #Stark's answer, if you want to drop the leading 0 from the left.
You can convert it from string to int, then convert it back to string.
concat('container1/','Directory1/','Year=',string(int(substring(utcNow(),0,4))),'/Month=',string(int(substring(utcnow(),5,2))),'/Day=',string(int(substring(utcnow(),8,2))),'/myfile.csv')

Azure Resource Manager - Convert value to 'lower'

I was recently using ARM templates to deploy multiple resources into Azure. While deploying Storage accounts, I ran into an issue which was due to some constraints put up by Azure like
Name of Storage Account should not contain upper case letters
Its max length should be 24.
I want this name from the user and can handle the 2nd issue using the "maxLength" property on 'parameters'. But for lower case, there is no such property in 'parameters' also I'm unable to find any function which will convert the user entered value to lower case.
What I expect:
Method to convert the user entered value in lower case.
Any other method to suit my use case.
Thanks in advance.
You should look at the string function reference of the ARM templates.
you need to create a variable (or just add those functions to the name input, like so:
"name": "[toLower(parameters('Name'))]"
or add a substring method, something like this:
"variables": {
"storageAccountName": "[tolower(concat('sawithsse', substring(parameters('storageAccountType'), 0, 2), uniqueString(subscription().id, resourceGroup().id)))]"
},

Resources