download files in azure vm using fileuri - azure

"fileUris": [
"https://files.blob.core.windows.net/extensions/test.sh"]
In an Azure scale set, does this part of extension download the file test.sh to the VM or call it directly from blob storage?

I'm assuming you are talking about the custom script extension for Azure virtual machines.
On its documentation page it reads:
The Custom Script Extension downloads and executes scripts on Azure
virtual machines. This extension is useful for post deployment
configuration, software installation, or any other configuration /
management task. Scripts can be downloaded from Azure storage or
GitHub, or provided to the Azure portal at extension run time. The
Custom Script extension integrates with Azure Resource Manager
templates, and can also be run using the Azure CLI, PowerShell, Azure
portal, or the Azure Virtual Machine REST API.
Highlighted are the relevant parts.
The extension work so that it first downloads and then executes the scripts you provide for it.
Edit: If you need to deploy some external resources you can upload them to your GitHub account or an Azure Storage Blob and download/read them from there.
See for example this answer for more details on how to download a file from a blob.
Invoke-WebRequest -Uri https://jasondisk2.blob.core.windows.net/msi/01.PNG -outfile 'C:\'
If you simply want to read the json file, then you can do as described here in this other answer.
$response = Invoke-RestMethod -Uri "https://yadayada:8080/bla"
$response.flag
Note: Invoke-RestMethod automatically converts the json response to a psobject.
As for the working directory. The extension downloads its files into the following directory
C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.*\Downloads\<n>
where <n> is a decimal integer which may change between executions of the extension. The 1.* value matches the actual, current typeHandlerVersion value of the extension.
For example, the actual directory could be
C:\Packages\Plugins\Microsoft.Compute.CustomScriptExtension\1.8\Downloads\2
See the troubleshooting section in the Azure documentation for more information.
Alternatively, for a Linux based system the path is similar to
/var/lib/waagent/custom-script/download/0/
see this page for more information.

Related

Azure form recognizer app invalid resource name

I'm traying to daploy an instance of the form recognizer app in Azure. For that I'm following the instructions in the documentation: https://learn.microsoft.com/en-us/azure/cognitive-services/form-recognizer/deploy-label-tool
I have created the docker instance and the connection, but the step to create the APP is failing.
This are the parameters I'm using:
Display Name: Test-form
Source Connection: <previuosly created connection>
Folder Path: None
Form Recognizer Service Uri: https://XXX-test.cognitiveservices.azure.com/
API Key: XXXXX
Description: None
And this is the error and getting:
I had the same error. It turned out to be due to incorrect SAS URI formatting because I generated and copied the SAS token via the Storage Accounts interface. It's much easier to get the correct format for the SAS URI if you generate it through the Storage Explorer (currently in Preview) as opposed to through the Storage Accounts.
If you read the documentation carefully it gives you a step by step guide
"To retrieve the SAS URL, open the Microsoft Azure Storage Explorer, right-click your container, and select Get shared access signature. Set the expiry time to some time after you'll have used the service. Make sure the Read, Write, Delete, and List permissions are checked, and click Create. Then copy the value in the URL section. It should have the form: https://.blob.core.windows.net/?"
Form Recognizer Documentation
The error messages point to a configuration issue with the AzureBlobStorageTemplate Thing. Most likely the containerName field for the Blob Storage Thing is empty or contains invalid characters
Ensure the containerName is a valid Azure storage container name.
Check https://learn.microsoft.com/en-us/rest/api/storageservices/Naming-and-Referencing-Containers--Blobs--and-Metadata for more information.
A container name must be a valid DNS name
The Connector loads and caches all configuration settings during startup. Any changes that you make to the configuration when troubleshooting are ignored until the Connector is restarted.
When creating the container connection, you must add the container into the SAS URI, such as
https://<storage-account>.blob.core.windows.net/<Enter-My-Container-Here>?<SAS Key>
You can also directly use the open source labeling tool, please see the section further down in the doc:
The OCR Form Labeling Tool is also available as an open-source project on GitHub. The tool is a web application built using React + Redux, and is written in TypeScript. To learn more or contribute, see OCR Form Labeling Tool.

Clear an App Service instance and upload new content from a zip file

On App Service, what's the best way of deploying new content from a zip file, such that it replaces any existing content?
Please note:
I am running on linux
I cannot use msdeploy
I cannot use git
I cannot use VSTS
It needs to be simple
It cant be prone to timing out
It has to be supported by all subscription levels of App Service
Commands should only return after their respective operation(s) have completed
I have access to ARM templates
Provided it isn't as difficult, I'm sure I could upload files to storage blobs
For more information, see this discussion here: https://github.com/projectkudu/kudu/issues/2367
There is a solution that consists in calling the ARM msdeploy provider to deploy a cloud hosted zip package. This requires no msdeploy on your client, so the fact that msdeploy technology is involved is mostly an implementation detail you can ignore.
There are a couple gotchas that I will call out at the end.
The steps are:
First, get your zip hosted in the cloud. e.g. I have a test one here you can play around with: https://davidebbostorage.blob.core.windows.net/arm/FunctionMsDeploy.zip (note that this zip uses special msdeploy packaging, but you can also use a plain old zip with just your files).
Then run the following command using cli 2.0, replacing your resource group, app name and zip url:
az resource update --resource-group MyRG --namespace Microsoft.Web --parent sites/MySite --resource-type Extensions --name MSDeploy --set properties.packageUri=https://davidebbostorage.blob.core.windows.net/arm/FunctionMsDeploy.zip --api-version 2015-08-01
This will result in the package getting deployed to your wwwroot, and any existing content that's not in the zip getting deleted. It's efficient as it won't touch any files that already exist and are identical to what's in the zip. So it's far faster than trying to clean out everything and unzipping clean (but results are identical).
Now a couple gotchas:
Due to what seems like a bug in CLI 2.0, I wasn't able to pass a URL that contains an equal sign, which rules out SAS URLs. I'll report that to them. For now, test the process with a public zip, like my test package above.
The command line is more complex than it should be. I will also ask the CLI team about this.

How to deploy package to Azure Web App using MSDeploy extension? (The value for one of the HTTP headers is not in the correct format)

I am trying to build a very simple Azure Resource Manager template to provision an App Service Plan, a Web App and immediately deploy package there using MSDeploy. I created a Resource Group project in Visual Studio and added Web App and MSDeploy extension. I basically followed this article: http://blogs.technet.com/b/georgewallace/archive/2015/05/10/deploying-a-website-with-content-through-visual-studio-with-resource-groups.aspx. I haven't customized deployment PowerShell script which comes with the project.
Here is the template: http://pastebin.com/raw/aFsMyg1W
Everything looks like it should work (package is uploaded to blob, web app is created), but deployment fails with message:
Resource Microsoft.Web/sites/extensions 'xg-test-webapp5/MSDeploy' failed with message 'The resource operation completed with terminal provisioning state 'Failed'.
There is an error message accessible via Kudu console (LogFiles/SiteExtensions/MSDeploy/appManagerLog.xml):
AppGallery Deploy Failed: 'Microsoft.WindowsAzure.StorageClient.StorageClientException: The value for one of the HTTP headers is not in the correct format
Full log:
Just for the reference, here is the content of the blob where the package was uploaded. It can be seen that it is accessible at the correct URL.
Any idea what is happening? Thanks
In your ARM template, the packageUri property for the MSDeploy extension resource is the concatenation of parameters: _artifactsLocation, webdeployPackageFolder and _artifactsLocationSasToken.
I tested your actual web deploy package blob Uri below.
https://xgartifacts.blob.core.windows.net/xg-test-rg-stageartifacts/deploy/package.zip
It is a publicly accessible blob, which means it can be downloaded without the SAS token.
Hence, you should not include the SAS Token in the packageUri property of your ARM template.
Hope this helps!
"packageUri": "[concat(parameters('_artifactsLocation'), '/', parameters('webdeployPackageFolder'), '/', parameters('webdeployPackageFileName'), parameters('_artifactsLocationSasToken'))]"

Azure Storage Blob Content type Converter

I need to convert approx 250k images from having a content type of application/octetstream to image/jpg
is there a powershell script I can utilise to do this or some sort of command code?
There is a script available in Windows Azure Script Center repository, where you can use to batch change the content type of your files.
They provide also a video on how to use it.
I don't think Windows Azure PowerShell Cmdlets has a readymade Cmdlet to do that. If you're open to use 3rd party product, you can try Cerebrata's Azure Management Cmdlets. It has a Set-BlobProperties cmdlet using which you can set the content type.
You can also do it through code as well. Essentially what you would do is fetch blobs from the blob container using ListBlobs or ListBlobsSegmented method and then iterate over these blobs and update the blob's properties via SetProperties method of CloudBlockBlob.

Trying to Create a Virtual Machine Deployment in Azure via Service Management API

Trying to Create a Virtual Machine Deployment in Azure via Service Management API.
But getting the 404 http error code , though the uri is correct.I am correctly setting the values in the below format,
https://management.core.windows.net//services/hostedservices//deployments/
Anything else is missing ? Also am setting the certificates for SSL authentication.All other services seems to work but this alone is throwing a 404 http error
you mentioned you are using this url:
https://management.core.windows.net//services/hostedservices//deployments/
are you inputing your subscription-id and hosted service on which you wish to deploy?
the url should look like this:
https://management.core.windows.net/<subscription-id>/services/hostedservices/<service-name>/deployments/
taken from http://msdn.microsoft.com/en-us/library/windowsazure/jj157194
though when using the above URL i was also getting 404 responses, i needed to remove the trailing slash at the end. (".../deployments" , not ".../deployments/")
after this i started getting BadRequest Responses but this is probably just because of the XML body not being generated properly.
hope it helps
I think you are asking about Windows Azure Virtual Machines. In that case you might not be using the correct newer Powershell cmdlets to create Azure Virtual Machines because when you make new Virtual Machine cmdlets you don't need to use the management URL. It is all done during very first call when you configure connection using PublishSettings file and then set your subscription. The steps to create a new Azure Virtual Machine using Powershell cmdlets are as below:
Get-AzurePublishSettingsFile (documentation is here)
Import-AzurePublishSettingsFile azuresettings.publishsettings
New-AzureVM ** (documentation/sample script is here)
If you are using PaaS Windows Azure Web/Worker Role then you will use:
New-AzureDeployment (documented here)
A list of all new Windows Azure Powershell CMDlets is documented here.
Finally it worked.There are some errors in MSDN documentation.
uri:https://management.core.windows.net/subscriptionID/services/hostedservices/servicename/deployments
No slash at the end, but MSDN documentation gives a slash at the end.

Resources