Skip to content
Closed
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ Release History
===============
upcoming
++++++
* 'az containerapp function list': List functions in a container app
* 'az containerapp function show': Show specific function in a container app
* 'az containerapp function keys show': Show specific function key in a container app
* 'az containerapp function keys list': List function keys in a container app
* 'az containerapp function keys set': Create a new or update an existing function key in a container app
* 'az containerapp function invocations summary': Get function invocation summary from Application Insights
* 'az containerapp function invocations traces': Get function invocation traces from Application Insights

1.2.0b5
++++++
Expand All @@ -21,6 +28,7 @@ upcoming
* 'az containerapp env premium-ingress': Deprecate `--min-replicas` and `--max-replicas` parameters, use workload profile scale instead.
* 'az containerapp sessionpool create/update': Support `--probe-yaml`
* 'az containerapp session stop': Support stop session for custom container sessions
* 'az containerapp debug': Support `--command` to run a command inside the container and exit

1.2.0b3
++++++
Expand Down
157 changes: 156 additions & 1 deletion src/containerapp/azext_containerapp/_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import requests

from azure.cli.core.azclierror import ResourceNotFoundError
from azure.cli.core.azclierror import ResourceNotFoundError, CLIError
from azure.cli.core.util import send_raw_request
from azure.cli.core.commands.client_factory import get_subscription_id
from azure.cli.command_modules.containerapp._clients import (
Expand Down Expand Up @@ -303,6 +303,161 @@ def list(cls, cmd, resource_group_name, container_app_name):
return policy_list


class ContainerAppFunctionsPreviewClient():
api_version = "2025-10-02-preview"

@classmethod
def list_functions_by_revision(cls, cmd, resource_group_name, container_app_name, revision_name):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/containerApps/{}/revisions/{}/functions?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
container_app_name,
revision_name,
cls.api_version)

r = send_raw_request(cmd.cli_ctx, "GET", request_url)
if not r:
raise CLIError(f"Error retrieving functions for revision '{revision_name}' of container app '{container_app_name}'.")
return r.json()

@classmethod
def get_function_by_revision(cls, cmd, resource_group_name, container_app_name, revision_name, function_name):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/containerApps/{}/revisions/{}/functions/{}?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
container_app_name,
revision_name,
function_name,
cls.api_version)

r = send_raw_request(cmd.cli_ctx, "GET", request_url)
if not r:
raise CLIError(f"Error retrieving function '{function_name}' for revision '{revision_name}' of container app '{container_app_name}'.")
return r.json()

@classmethod
def list_functions(cls, cmd, resource_group_name, container_app_name):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/containerApps/{}/functions?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
container_app_name,
cls.api_version)

r = send_raw_request(cmd.cli_ctx, "GET", request_url)
if not r:
raise CLIError(f"Error retrieving functions for container app '{container_app_name}'.")
return r.json()

@classmethod
def get_function(cls, cmd, resource_group_name, container_app_name, function_name):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/containerApps/{}/functions/{}?api-version={}"
request_url = url_fmt.format(
management_hostname.strip('/'),
sub_id,
resource_group_name,
container_app_name,
function_name,
cls.api_version)

r = send_raw_request(cmd.cli_ctx, "GET", request_url)
if not r:
raise CLIError(f"Error retrieving function '{function_name}' for container app '{container_app_name}'.")
return r.json()

@classmethod
def show_function_keys(cls, cmd, resource_group_name, name, key_type, key_name, function_name=None, revision_name=None, replica_name=None, container_name=None):
from ._utils import execute_function_admin_command

command_fmt = ""
if key_type != "functionKey":
command_fmt = "/bin/azure-functions-admin keys show --key-type {} --key-name {}"
command = command_fmt.format(key_type, key_name)
else:
command_fmt = "/bin/azure-functions-admin keys show --key-type {} --key-name {} --function-name {}"
command = command_fmt.format(key_type, key_name, function_name)

r = execute_function_admin_command(
cmd=cmd,
resource_group_name=resource_group_name,
name=name,
command=command,
revision_name=revision_name,
replica_name=replica_name,
container_name=container_name
)
if not r:
raise CLIError(f"Error retrieving function key '{key_name}' of type '{key_type}'.")
return r

@classmethod
def list_function_keys(cls, cmd, resource_group_name, name, key_type, function_name=None, revision_name=None, replica_name=None, container_name=None):
from ._utils import execute_function_admin_command

command_fmt = ""
if key_type != "functionKey":
command_fmt = "/bin/azure-functions-admin keys list --key-type {}"
command = command_fmt.format(key_type)
else:
command_fmt = "/bin/azure-functions-admin keys list --key-type {} --function-name {}"
command = command_fmt.format(key_type, function_name)

r = execute_function_admin_command(
cmd=cmd,
resource_group_name=resource_group_name,
name=name,
command=command,
revision_name=revision_name,
replica_name=replica_name,
container_name=container_name
)
if not r:
raise CLIError(f"Error retrieving function keys of type '{key_type}'.")
return r

@classmethod
def set_function_keys(cls, cmd, resource_group_name, name, key_type, key_name, key_value, function_name=None, revision_name=None, replica_name=None, container_name=None):
"""Set/Update function keys based on key type"""
from ._utils import execute_function_admin_command

command_fmt = ""
if key_type != "functionKey":
command_fmt = "/bin/azure-functions-admin keys set --key-type {} --key-name {}"
command = command_fmt.format(key_type, key_name)
else:
command_fmt = "/bin/azure-functions-admin keys set --key-type {} --key-name {} --function-name {}"
command = command_fmt.format(key_type, key_name, function_name)

if key_value is not None:
command += " --key-value {}".format(key_value)

r = execute_function_admin_command(
cmd=cmd,
resource_group_name=resource_group_name,
name=name,
command=command,
revision_name=revision_name,
replica_name=replica_name,
container_name=container_name
)
if not r:
raise CLIError(f"Error setting function key '{key_name}' of type '{key_type}'.")
return r


class DaprComponentResiliencyPreviewClient():
api_version = PREVIEW_API_VERSION

Expand Down
139 changes: 135 additions & 4 deletions src/containerapp/azext_containerapp/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,11 @@
- name: Create a container app and deploy a model from Azure AI Foundry
text: |
az containerapp up -n my-containerapp -l westus3 --model-registry azureml --model-name Phi-4 --model-version 7
- name: Create an Azure Functions on Azure Container Apps (kind=functionapp)
- name: Create an Azure Functions on Container Apps (kind=functionapp)
text: |
az containerapp up -n my-containerapp --image my-app:v1.0 --kind functionapp
"""


helps['containerapp replica count'] = """
type: command
short-summary: Count of a container app's replica(s)
Expand All @@ -179,6 +178,135 @@
az containerapp replica count -n my-containerapp -g MyResourceGroup
"""

helps['containerapp function'] = """
type: group
short-summary: Commands related to Azure Functions on Container Apps.
"""

helps['containerapp function list'] = """
type: command
short-summary: List all functions in an Azure Functions on Container Apps.
long-summary: |
--revision is required only if the app is not in single revision mode.
Run to check activerevisionmode: az containerapp show -n my-containerapp -g MyResourceGroup --query properties.configuration.activeRevisionsMode
examples:
- name: List all functions in an Azure Functions on Container Apps. (single active revision mode)
text: |
az containerapp function list -n my-containerapp -g MyResourceGroup
- name: List all functions in an Azure Functions on Container Apps for a specific revision.
text: |
az containerapp function list -n my-containerapp -g MyResourceGroup --revision MyRevision
"""

helps['containerapp function show'] = """
type: command
short-summary: Get details of a function in an Azure Functions on Container Apps.
long-summary: |
--revision is required only if the app is not in single revision mode.
Run to check activerevisionmode: az containerapp show -n my-containerapp -g MyResourceGroup --query properties.configuration.activeRevisionsMode
examples:
- name: Show details of a function in an Azure Functions on Container Apps. (single active revision mode)
text: |
az containerapp function show -n my-containerapp -g MyResourceGroup --function-name MyFunction
- name: Show details of a function in an Azure Functions on Container Apps for a specific revision.
text: |
az containerapp function show -n my-containerapp -g MyResourceGroup --function-name MyFunction --revision MyRevision
"""

helps['containerapp function keys'] = """
type: group
short-summary: Commands for keys management in an Azure Functions on Container Apps.
"""

helps['containerapp function keys show'] = """
type: command
short-summary: Show specific function key in an Azure Functions on Container Apps.
examples:
- name: Show a function key for a specific function in an Azure Functions on Container Apps.
text: |
az containerapp function keys show -n my-containerapp -g MyResourceGroup --key-type functionKey --key-name default --function-name MyFunctionName
- name: Show a host key for an Azure Functions on Container Apps.
text: |
az containerapp function keys show -n my-containerapp -g MyResourceGroup --key-type hostKey --key-name default
- name: Show a master key for an Azure Functions on Container Apps.
text: |
az containerapp function keys show -n my-containerapp -g MyResourceGroup --key-type masterKey --key-name _master
- name: Show a system key for an Azure Functions on Container Apps.
text: |
az containerapp function keys show -n my-containerapp -g MyResourceGroup --key-type systemKey --key-name MyKeyName
"""

helps['containerapp function keys list'] = """
type: command
short-summary: List function keys in an Azure Functions on Container Apps.
examples:
- name: List function keys for a specific function in an Azure Functions on Container Apps.
text: |
az containerapp function keys list -n my-containerapp -g MyResourceGroup --key-type functionKey --function-name MyFunctionName
- name: List host keys for an Azure Functions on Container Apps.
text: |
az containerapp function keys list -n my-containerapp -g MyResourceGroup --key-type hostKey
- name: List master keys for an Azure Functions on Container Apps.
text: |
az containerapp function keys list -n my-containerapp -g MyResourceGroup --key-type masterKey
- name: List system keys for an Azure Functions on Container Apps.
text: |
az containerapp function keys list -n my-containerapp -g MyResourceGroup --key-type systemKey
"""

helps['containerapp function keys set'] = """
type: command
short-summary: Create or update specific function key in an Azure Functions on Container Apps.
examples:
- name: Create or update a function key for a specific function in an Azure Functions on Container Apps.
text: |
az containerapp function keys set -n my-containerapp -g MyResourceGroup --key-type functionKey --key-name default --key-value MyKeyValue --function-name MyFunctionName
- name: Create or update a host key for an Azure Functions on Container Apps.
text: |
az containerapp function keys set -n my-containerapp -g MyResourceGroup --key-type hostKey --key-name default --key-value MyKeyValue
- name: Create or update the master key for an Azure Functions on Container Apps.
text: |
az containerapp function keys set -n my-containerapp -g MyResourceGroup --key-type masterKey --key-name _master --key-value MyKeyValue
- name: Create or update a system key for an Azure Functions on Container Apps.
text: |
az containerapp function keys set -n my-containerapp -g MyResourceGroup --key-type systemKey --key-name MyKeyName --key-value MyKeyValue
"""

helps['containerapp function invocations'] = """
type: group
short-summary: Commands to get function invocation data and traces from Application Insights.
"""

helps['containerapp function invocations summary'] = """
type: command
short-summary: Get function invocation summary from Application Insights.
examples:
- name: Get invocation summary for a function with default timespan (30 days)
text: |
az containerapp function invocations summary -n my-containerapp -g MyResourceGroup --function-name MyFunction
- name: Get invocation summary for a function with specific timespan
text: |
az containerapp function invocations summary -n my-containerapp -g MyResourceGroup --function-name MyFunction --timespan 7d
- name: Get invocation summary for a function in a specific revision
text: |
az containerapp function invocations summary -n my-containerapp -g MyResourceGroup --function-name MyFunction --revision MyRevision
"""

helps['containerapp function invocations traces'] = """
type: command
short-summary: Get function invocation traces from Application Insights.
examples:
- name: Get invocation traces for a function with default timespan (30 days)
text: |
az containerapp function invocations traces -n my-containerapp -g MyResourceGroup --function-name MyFunction
- name: Get invocation traces for a function with specific timespan
text: |
az containerapp function invocations traces -n my-containerapp -g MyResourceGroup --function-name MyFunction --timespan 24h
- name: Get invocation traces for a function in a specific revision
text: |
az containerapp function invocations traces -n my-containerapp -g MyResourceGroup --function-name MyFunction --revision MyRevision
"""

# Environment Commands
helps['containerapp env'] = """
type: group
Expand Down Expand Up @@ -920,7 +1048,7 @@
az containerapp create -n my-containerapp -g MyResourceGroup \\
--image my-app:v1.0 --environment MyContainerappEnv \\
--enable-java-agent
- name: Create an Azure Functions on Azure Container Apps (kind=functionapp)
- name: Create an Azure Functions on Container Apps (kind=functionapp)
text: |
az containerapp create -n my-containerapp -g MyResourceGroup \\
--image my-app:v1.0 --environment MyContainerappEnv \\
Expand Down Expand Up @@ -2308,11 +2436,14 @@

helps['containerapp debug'] = """
type: command
short-summary: Open an SSH-like interactive shell within a container app debug console.
short-summary: Open an SSH-like interactive shell within a container app debug console or execute a command inside the container and exit.
examples:
- name: Debug by connecting to a container app's debug console by replica, revision and container
text: |
az containerapp debug -n MyContainerapp -g MyResourceGroup --revision MyRevision --replica MyReplica --container MyContainer
- name: Debug by executing a command inside a container app and exit
text: |
az containerapp debug -n MyContainerapp -g MyResourceGroup --revision MyRevision --replica MyReplica --container MyContainer --command "echo Hello World"
"""

helps['containerapp label-history'] = """
Expand Down
Loading
Loading