The content below is taken from the original (Azure CLI 2.0: new commands, features; available now in Azure Cloud Shell), to continue reading please visit the site. Remember to respect the Author & Copyright.
As announced previously on this blog, we continue to make constant progress in adding new features to and stabilizing Azure CLI 2.0 over last several months.
At Microsoft Build 2017, we announced new functionality available in Azure CLI 2.0 through these new or significantly enhanced command modules – appservices, cdn, cognitive services, cosmosdb, data lake analytics and store, dev/test labs, functions, monitor, mysql, postgres, service fabric client, vsts.
Some of these changes include new syntax and modified names for existing CLI commands. You can continue to use the previous CLI commands for another couple of releases, but we will deprecate these after that and you will need to start using the new commands. Our recommendation is that you should switch to the new commands as soon as possible. We added a deprecation warning to the commands that we will remove in coming releases (all of them are currently in “preview” release mode).
Over the past 2-3 months, we have seen increased engagement from our customers and new developers in Azure CLI 2.0 which is very encouraging. Although most of the feedback has been positive so far, there are a couple of areas where the experience hasn’t been optimal. Install issues, especially on Windows, have been an oft-cited complaint from many of our early adopters. Based on this, we are now releasing a MSI installer for Azure CLI 2.0 for Windows. This will take the complexity of having the correct versions of Python and other dependencies installed in the correct folders, which will also help with future upgrades and uninstall scenarios of Azure CLI. For Mac and Linux, we already have Curl, Apt-Get, PIP installers available that make the install experience seamless. Please see the updated install page for detailed instructions on how to install or upgrade to latest versions of Azure CLI 2.0.
We plan on releasing more native installers for other supported platforms in coming months.
Interactive mode and Azure Cloud Shell
In early April, we announced a separate, stand-alone install to run Azure CLI 2.0 in interactive mode. Based on feedback from customers, we are now merging this functionality directly into Azure CLI 2.0, so that you don’t need a separate install to run Azure CLI 2.0 in interactive mode. You can now launch the CLI into interactive mode by simply running the “interactive” command.
After this, Azure CLI 2.0 runs within its own interactive shell which provides command dropdowns, auto-cached suggestions, combined with on-the-fly documentation, including examples of how each command is used. Interactive mode is really useful when learning Azure CLI 2.0’s capabilities, command structures and output formats. It is optimized for single command executions (as opposed to running automation scripts).
You can exit out of the interactive mode by running “quit” within this mode.
In addition to running Azure CLI on your own client machine, you can also run it in Azure Cloud Shell directly from Azure Management Portal. Azure Cloud Shell is a browser-based shell experience maintained by Microsoft to manage Azure resources. Cloud Shell comes installed with popular command-line tools and attaches an Azure file share to persist storage across sessions. This allows you to run CLI 2.0 commands directly in the browser using the login credentials with which you are logged on to in the Azure Management Portal. This is really useful when you don’t have ready access to your own machine with all of the necessary client side tools for Azure installed.
For running Azure CLI 2.0 in your own Bash or command.exe environment on your client machines, you can still install Azure CLI 2.0 using all the install mechanisms discussed above.
This latest release of Azure CLI 2.0 also comes up with many performance improvements. You should see significantly reduced times for many commonly used commands and usage scenarios. This is an area that we are constantly working on and trying to improve. So, if you are experiencing non-optimal experience in running your commands or automation scripts, we are interested in hearing from you and in learning more about your usage scenarios, patterns and configurations. Please feel free to email us directly at [email protected] You can also use the “az feedback” command directly from within the CLI to send us your feedback.
New commands for App Services, MySQL and Azure Functions
Azure CLI 2.0 gives you full management capability to create and manage your app services on Azure. Your web apps are created inside an app service plan which defines the resources (locations, number of workers) and the SKU (based on the billing plan chosen) for your hosted applications. Within an app service plan, you can create multiple web apps and manage them (start, stop, update).
Azure now also provides fully managed services for running MySQL and PostgreSQL databases on the cloud. And you can use the Azure CLI 2.0 to configure and manage these as well. Here are some Azure CLI 2.0 commands that you can use to deploy a PHP website with MySQL to Azure:
Create MySQL database on Azure and use it in your web app locally
First create a MySQL database and an associated firewall rule in your Azure subscription.
# login to your Azure account from the Azure CLI az login # select the Azure subscription you want to use in your account az account set –-subscription “My Demos” # create a new resource group in your subscription (or skip this step if # using an existing resource group) az group create –-location westus2 –-name MyResourceGroup # create a new server in Azure MySQL database within the selected resource # group az mysql server create –-name MySQLServer –-resource-group MyResourceGroup ` --location westus2 –-user AdminUser –-password AdminPassword # create a new firewall rule for your MySQL database to allow client # connections az mysql server firewall-rule create –-name MyFirewallRule –-server ` MySQLServer –-resource-group MyResourceGroup –-start-ip-address 0.0.0.0 ` --end-ip-address 255.255.255.255
Now you can connect to this MySQL server from your command window using the admin username and password specified above while creating the server. Once connected, use MySQL commands to create a new database and a new database user in the MySQL server. You can then configure your PHP web app to use this new database running on Azure MySQL by updating the connection string and database username and password that you specified while creating the database. Your app running on local machine should be able to connect to this database on Azure MySQL at this point.
Host your web app on Azure along with the MySQL database
Then create an Azure App Service and a Web App inside it and set it up to take source updates from your local GIT repository.
# create new app service plan in the selected resource group az appservice plan create –-name MyAppSvcPlan –-resource-group ` MyResourceGroup –-sku FREE # create a new web app in the above app service plan, set PHP runtime version # and configure for local Git deployment (all in one simple command) az webapp create -g MyResourceGroup -n MyWebApp --plan MyAppSvcPlan --runtime "php|7.0" --deployment-local-git # set the deployment user for the web app to deploy it from your local # machine using Git az webapp deployment user set –-user-name LocalGitUser –-password ` LocalUserPassword
Set up the Azure web app to work with the local Azure MySQL database.
# update the web app config settings to use MySQL database az webapp config appsettings update –-name MyWebApp –-resource-group ` MyResourceGroup –-settings DB_HOST=MySQLServer.windows.net ` DB_DATABASE=”sampledb” DB_USERNAME=”[email protected]” ` DB_PASSWORD=”dbuser_password”
Now you can update your PHP web app to connect to this MySql database by updating the .env and database.php files. Generate a new application key and save it into your .env settings of the PHP app.
# update app-key with generated application key for your web app on Azure az webapp config appsettings update –-name MyWebApp –-resource-group ` MyResourceGroup –-settings APP_KEY=”generated app key” APP_DEBUG=”true”
After this you can use GIT commands (GIT remote and GIT push) to push your web app to Azure and have it deployed. Your web app is now ready and running on Azure.
Look at this article for step-by-step instructions on how to deploy a PHP website with MySQL to Azure App Services.
You can use other CLI commands to change app service plan, scale the web app, start or stop the web app etc.
Create Azure Functions using Azure CLI 2.0
Azure Functions is a solution for easily running small pieces of code, or “functions”, in the cloud. You can write just the code you want to run in many different languages that are supported and deploy it to Azure without worrying about the application or infrastructure needed to host and run it. Azure CLI 2.0 makes it easy to deploy and manage this code through the command line.
To create and deploy a piece code to Azure Functions, you can use this simple but powerful command:
az functionapp create -g MyFunctionRG1 -n myfunction -s myfuncstg -c westus2 –u http://bit.ly/2q4UZuJ
In the above command, you define the name for your new function app, specify the resource group and storage account along with the consumption plan you want to create it in. Finally, you can also point directly to your GIT based repository where you have your source code for the function app. The function is created and the source code from your GIT repo is deployed in a single step.
Once this is done, your function is ready to run. Go to Azure management portal, get the URL to the function and you can directly run that URL in a browser or a client side app to see the results of the function code.
Simple yet powerful – that’s what Azure CLI 2.0 is. It provides smart defaults, asks for minimum number of parameters to run the commands, does multiple steps in the background but also provides you full power of controlling what happens with many options and other parameters you can set.
Start using Azure CLI 2.0 today!
Whether you are an existing CLI user, or you are starting a new Azure project, it’s easy to get started with the CLI directly, or in the Azure Cloud Shell. Learn and master the command line with our updated docs and samples.
Azure CLI 2.0 is open source and on GitHub.
In the next few months, we’ll provide more updates. As ever, we want your ongoing feedback! Customers using the commands, that are now in GA release, in production can contact Azure Support for any issues, reach out via StackOverflow using the azure-cli tag, or email us directly at [email protected]. You can also use the “az feedback” command directly from within the CLI to send us your feedback.