Functions-as-a-service offerings, such as Azure Functions, are little more than just pure code. Still, they aren't...
just for developers; several scripting languages open up new opportunities for admins and systems analysts as well.
Scripting options for Azure Functions
Azure Functions is a collection of event-driven application components that can interact with other Azure services. It's useful for asynchronous tasks, such as data ingestion and processing, extract, transform and load processes or other data pipelines, as well as microservices or cloud service integration.
In general, functions are well-suited as integration and scripting tools for legacy enterprise applications due to their event-driven, lightweight and infrastructure-free nature. The ability to use familiar languages, such as PowerShell, Python and Node.js, makes that case even stronger. Since PowerShell is popular with Windows IT shops and Azure users, the best practices below focus on that particular scripting language but apply to others as well.
PowerShell support evolves
PowerShell support for Azure Functions, introduced in 2016 as part of the open source Azure WebJobs software development kit, is still considered experimental and is subject to change. One potential roadblock is that the sandbox security model, which is necessary to deliver Functions as a shared service, isn't consistent with how many PowerShell users interact with their environment, noted a Microsoft developer on GitHub.
Microsoft suggests using Azure Automation over Functions for production scenarios until Microsoft enhances PowerShell support, the developer said. Still, IT teams can use PowerShell functions as part of many complex applications.
PowerShell for Azure Functions
The initial implementation of PowerShell for Azure Functions uses PowerShell version 4 and only supports scripts (PS1 files), not modules (PSM1 files), which makes it best for simpler tasks and rapid development. To use PowerShell modules in Azure Functions, users can update the PSModulepath environment variable to point to a folder that contains custom modules and connect to it through FTP.
Azure Functions vs. Logic Apps
Some developers question the excitement around Azure Functions when the vendor already offers Logic Apps, which has a drag-and-drop GUI for event-driven development. Although the services seemingly overlap, they are complementary.
Functions are code modules triggered by an event, while Logic Apps are workflows triggered by an event. Additionally, Logic Apps can contain functions as part of the workflow. The Logic Apps editor natively supports functions creation and debugging, which means developers can code in a single environment.
Logic Apps is best for complex workflows that use multiple applications, while Azure Functions is best for custom microservices or code modules that execute quickly and integrate with other services.
When you use scripts, pass data to PowerShell functions through files or environment variables, because a function won't store or cache the runtime environment. Incoming data to a function, via an event trigger or input binding, is passed using files that are accessed in PowerShell through environment variables. The same scheme works for data output. Since the input data is just a raw file, users must know what to expect and parse accordingly. Functions itself won't format data but will support most formats, including:
- stream; and
PowerShell functions can be triggered by HTTP requests, an Azure service queue, such as when a message is added to a specified storage queue, or a timer (see Figure 1). Developers can create Azure Functions with the Azure portal, Visual Studio -- C# functions only -- or a local code editor and integrated development environment, although the portal is the easiest option.
Azure Functions works the same whether the code is in C#, PowerShell or Python, which enables teams to use a language with which they have expertise or can easily master. The power of Functions stems from its integration with other Azure services and built-in runtime environments. Writing as a function is more efficient than creating a standalone app for simple tasks, such as triggering a webhook from an HTTP request.
While PowerShell is an attractive option for Windows teams, they need to proceed with caution since support for Azure Functions is still a work in progress. The implementation details will likely change, however, for the better.
Adopt these best practices for Azure Functions
Compare Azure Functions and Amazon Web Services Lambda for serverless computing
Peel back the layers of Azure cloud services