Skip to content

Commit 9102422

Browse files
Modify Samples to Call Function App and Web App Samples via Default Hostname (#76)
* Added azlocal start-interception to all README files * Fix Web App + SQL Sample * Change secret name to be compliant with validate.sh * updated runner * skip if already exists * remove the pre-existing microsoft-prod.list * upgraded azurerm provider * Modify Samples to Call Function App and Web App Samples via Default Hostname * Fixed resource group name --------- Co-authored-by: Dris.S <idrissardary@outlook.com>
1 parent 9d77427 commit 9102422

14 files changed

Lines changed: 81 additions & 1086 deletions

File tree

samples/function-app-managed-identity/python/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ All deployment methods have been fully tested with both user-assigned and system
8686
8787
## Test
8888

89-
Once the resources and serverless application have been deployed, you can use the `test.sh` script below to copy a sample file to the `input` container and monitor whether the Azure Functions App processes the input blob file and generates a result file in the `output` container.
89+
Once the resources and serverless application have been deployed, you can use the [test.sh](./scripts/test.sh) script below to copy a sample file to the `input` container and monitor whether the Azure Functions App processes the input blob file and generates a result file in the `output` container.
9090

9191
```bash
9292
#!/bin/bash

samples/function-app-service-bus/dotnet/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Getting IP address for container [ls-local-func-test-tdkqjh]...
105105
IP address [172.17.0.7] retrieved successfully for container [ls-local-func-test-tdkqjh]
106106
Getting the host port mapped to internal port 80 in container [ls-local-func-test-tdkqjh]...
107107
Mapped host port [42330] retrieved successfully for container [ls-local-func-test-tdkqjh]
108-
Calling HTTP trigger function to retrieve the last [10] greetings via emulator...
108+
Calling HTTP trigger function to retrieve the last [100] greetings via hostname [babo-func-test.azurewebsites.azure.localhost.localstack.cloud:4566]...
109109
{
110110
"requester": {
111111
"sent": [

samples/function-app-service-bus/dotnet/scripts/call-http-trigger.sh

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ call_http_trigger_function() {
117117
# Get the container IP address
118118
echo "Getting IP address for container [$container_name]..."
119119
container_ip=$(get_docker_container_ip_address_by_name "$container_name")
120-
greeting_count=10
120+
greeting_count=100
121121

122122
if [ $? -eq 0 ] && [ -n "$container_ip" ]; then
123123
echo "IP address [$container_ip] retrieved successfully for container [$container_name]"
@@ -137,15 +137,12 @@ call_http_trigger_function() {
137137
exit 1
138138
fi
139139

140-
# Retrieve LocalStack proxy port
141-
proxy_port=$(curl http://localhost:4566/_localstack/proxy -s | jq '.proxy_port')
142-
143-
if [ -n "$proxy_port" ]; then
144-
# Call the GetGreetings HTTP trigger function to retrieve the last greetings via emulator
145-
echo "Calling HTTP trigger function to retrieve the last [$greeting_count] greetings via emulator..."
146-
curl --proxy "http://localhost:$proxy_port/" -s "http://$function_host_name/api/greetings?count=$greeting_count" | jq
140+
if [ -n "$function_host_name" ]; then
141+
# Call the GetGreetings HTTP trigger function to retrieve the last greetings via the function hostname
142+
echo "Calling HTTP trigger function to retrieve the last [$greeting_count] greetings via function hostname [$function_host_name]..."
143+
curl -s "http://$function_host_name/api/greetings?count=$greeting_count" | jq
147144
else
148-
echo "Failed to retrieve LocalStack proxy port"
145+
echo "Failed to retrieve function hostname"
149146
fi
150147

151148
if [ -n "$container_ip" ]; then

samples/function-app-service-bus/dotnet/scripts/deploy.sh

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,23 @@ PE_NAMES=(
4949
"${PREFIX}-queue-storage-pe-${SUFFIX}"
5050
"${PREFIX}-table-storage-pe-${SUFFIX}"
5151
)
52-
PE_GROUP_IDS=("namespace" "blob" "queue" "table")
53-
PE_CONNECTION_NAMES=("servicebus-connection" "blob-connection" "queue-connection" "table-connection")
54-
PE_DNS_ZONES=("privatelink.servicebus.windows.net" "privatelink.blob.core.windows.net" "privatelink.queue.core.windows.net" "privatelink.table.core.windows.net")
55-
PE_DNS_ZONE_LABELS=("servicebus-zone" "blob-zone" "queue-zone" "table-zone")
52+
PE_GROUP_IDS=(
53+
"namespace"
54+
"blob" "queue"
55+
"table"
56+
)
57+
PE_CONNECTION_NAMES=(
58+
"servicebus-connection"
59+
"blob-connection"
60+
"queue-connection"
61+
"table-connection"
62+
)
63+
PE_DNS_ZONES=(
64+
"privatelink.servicebus.windows.net"
65+
"privatelink.blob.core.windows.net"
66+
"privatelink.queue.core.windows.net"
67+
"privatelink.table.core.windows.net"
68+
)
5669

5770
# Change the current directory to the script's directory
5871
cd "$CURRENT_DIR" || exit
@@ -640,7 +653,6 @@ for i in "${!PE_NAMES[@]}"; do
640653
PE_RESOURCE_ID="${PE_RESOURCE_IDS[$i]}"
641654
PE_CONNECTION="${PE_CONNECTION_NAMES[$i]}"
642655
PE_DNS_ZONE="${PE_DNS_ZONES[$i]}"
643-
PE_DNS_ZONE_LABEL="${PE_DNS_ZONE_LABELS[$i]}"
644656

645657
# Check if the private endpoint already exists
646658
echo "Checking if private endpoint [$PE_NAME] exists in the [$RESOURCE_GROUP_NAME] resource group..."
@@ -679,15 +691,15 @@ for i in "${!PE_NAMES[@]}"; do
679691

680692
# Check if the private DNS zone group is already created
681693
echo "Checking if the private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PE_NAME] private endpoint already exists..."
682-
az network private-endpoint dns-zone-group show \
694+
NAME=$(az network private-endpoint dns-zone-group show \
683695
--resource-group "$RESOURCE_GROUP_NAME" \
684696
--endpoint-name "$PE_NAME" \
685697
--name "$PRIVATE_DNS_ZONE_GROUP_NAME" \
686698
--query name \
687699
--output tsv \
688-
--only-show-errors &>/dev/null
700+
--only-show-errors)
689701

690-
if [[ $? != 0 ]]; then
702+
if [[ -z $NAME ]]; then
691703
echo "No private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PE_NAME] private endpoint actually exists"
692704
echo "Creating private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PE_NAME] private endpoint..."
693705

@@ -697,7 +709,7 @@ for i in "${!PE_NAMES[@]}"; do
697709
--resource-group "$RESOURCE_GROUP_NAME" \
698710
--endpoint-name "$PE_NAME" \
699711
--private-dns-zone "$PE_DNS_ZONE" \
700-
--zone-name "$PE_DNS_ZONE_LABEL" \
712+
--zone-name "$PE_DNS_ZONE" \
701713
--only-show-errors 1>/dev/null
702714

703715
if [[ $? == 0 ]]; then
@@ -716,26 +728,6 @@ if [ $DEPLOY -eq 0 ]; then
716728
exit 0
717729
fi
718730

719-
# Check if the application insights az extension is already installed
720-
echo "Checking if [application-insights] az extension is already installed..."
721-
az extension show --name application-insights &>/dev/null
722-
723-
if [[ $? == 0 ]]; then
724-
echo "[application-insights] az extension is already installed"
725-
else
726-
echo "[application-insights] az extension is not installed. Installing..."
727-
728-
# Install application-insights az extension
729-
az extension add --name application-insights 1>/dev/null
730-
731-
if [[ $? == 0 ]]; then
732-
echo "[application-insights] az extension successfully installed"
733-
else
734-
echo "Failed to install [application-insights] az extension"
735-
exit
736-
fi
737-
fi
738-
739731
# Check if the application insights component already exists
740732
echo "Checking if [$APPLICATION_INSIGHTS_NAME] Application Insights component exists in the [$RESOURCE_GROUP_NAME] resource group..."
741733
az monitor app-insights component show \
@@ -1061,7 +1053,7 @@ if ! az appservice plan show \
10611053
--name $APP_SERVICE_PLAN_NAME \
10621054
--resource-group $RESOURCE_GROUP_NAME \
10631055
--location $LOCATION \
1064-
--sku B1 \
1056+
--sku S1 \
10651057
--is-linux \
10661058
--tags $TAGS \
10671059
--only-show-errors 1>/dev/null; then
@@ -1162,6 +1154,7 @@ az functionapp config appsettings set \
11621154
--name $FUNCTION_APP_NAME \
11631155
--resource-group $RESOURCE_GROUP_NAME \
11641156
--settings \
1157+
APPLICATIONINSIGHTS_AUTHENTICATION_STRING="ClientId=${CLIENT_ID};Authorization=AAD" \
11651158
AZURE_CLIENT_ID="$CLIENT_ID" \
11661159
SCM_DO_BUILD_DURING_DEPLOYMENT=false \
11671160
FUNCTIONS_WORKER_RUNTIME=${RUNTIME,,} \
@@ -1457,4 +1450,4 @@ fi
14571450

14581451
# Print the list of resources in the resource group
14591452
echo "Listing resources in resource group [$RESOURCE_GROUP_NAME]..."
1460-
az resource list --resource-group "$RESOURCE_GROUP_NAME" --output table
1453+
az resource list --resource-group "$RESOURCE_GROUP_NAME" --output table

samples/function-app-storage-http/dotnet/README.md

Lines changed: 1 addition & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -163,194 +163,10 @@ All deployment methods have been fully tested against Azure and the LocalStack f
163163

164164
Use the [call-http-triggers.sh](./scripts/call-http-triggers.sh) script to quickly test the sample's HTTP-triggered Azure Functions and verify player status or game session details. The script below demonstrates three methods for calling HTTP-triggered functions:
165165

166-
1. **Through the LocalStack for Azure emulator**: Call the function app via the emulator using its default host name. The emulator acts as a proxy to the function app.
166+
1. **Via the default hostname**: Call the function app via the default hostname `<function-app-name>.azurewebsites.azure.localhost.localstack.cloud:4566`.
167167
2. **Via localhost and host port mapped to the container's port**: Use `127.0.0.1` with the host port mapped to the container's port `80`.
168168
3. **Via container IP address**: Use the app container's IP address on port `80`. This technique is only available when accessing the function app from the Docker host machine.
169169

170-
```bash
171-
#!/bin/bash
172-
173-
get_docker_container_name_by_prefix() {
174-
local app_prefix="$1"
175-
local container_name
176-
177-
# Check if Docker is running
178-
if ! docker info >/dev/null 2>&1; then
179-
echo "Error: Docker is not running" >&2
180-
return 1
181-
fi
182-
183-
echo "Looking for containers with names starting with [$app_prefix]..." >&2
184-
185-
# Find the container using grep
186-
container_name=$(docker ps --format "{{.Names}}" | grep "^${app_prefix}" | head -1)
187-
188-
if [ -z "$container_name" ]; then
189-
echo "Error: No running container found with name starting with [$app_prefix]" >&2
190-
return 1
191-
fi
192-
193-
echo "Found matching container [$container_name]" >&2
194-
echo "$container_name"
195-
}
196-
197-
get_docker_container_ip_address_by_name() {
198-
local container_name="$1"
199-
local ip_address
200-
201-
if [ -z "$container_name" ]; then
202-
echo "Error: Container name is required" >&2
203-
return 1
204-
fi
205-
206-
# Get IP address
207-
ip_address=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' "$container_name")
208-
209-
if [ -z "$ip_address" ]; then
210-
echo "Error: Container [$container_name] has no IP address assigned" >&2
211-
return 1
212-
fi
213-
214-
echo "$ip_address"
215-
}
216-
217-
get_docker_container_port_mapping() {
218-
local container_name="$1"
219-
local container_port="$2"
220-
local host_port
221-
222-
if [ -z "$container_name" ] || [ -z "$container_port" ]; then
223-
echo "Error: Container name and container port are required" >&2
224-
return 1
225-
fi
226-
227-
# Get host port mapping
228-
host_port=$(docker inspect -f "{{(index (index .NetworkSettings.Ports \"${container_port}/tcp\") 0).HostPort}}" "$container_name")
229-
230-
if [ -z "$host_port" ]; then
231-
echo "Error: No host port mapping found for container [$container_name] port [$container_port]" >&2
232-
return 1
233-
fi
234-
235-
echo "$host_port"
236-
}
237-
238-
call_http_trigger_functions() {
239-
# Get the function app name
240-
echo "Getting function app name..."
241-
function_app_name=$(azlocal functionapp list --query '[0].name' --output tsv)
242-
243-
if [ -n "$function_app_name" ]; then
244-
echo "Function app [$function_app_name] successfully retrieved."
245-
else
246-
echo "Error: No function app found"
247-
exit 1
248-
fi
249-
250-
# Get the resource group name
251-
echo "Getting resource group name for function app [$function_app_name]..."
252-
resource_group_name=$(azlocal functionapp list --query '[0].resourceGroup' --output tsv)
253-
254-
if [ -n "$resource_group_name" ]; then
255-
echo "Resource group [$resource_group_name] successfully retrieved."
256-
else
257-
echo "Error: No resource group found for function app [$function_app_name]"
258-
exit 1
259-
fi
260-
261-
# Get the the default host name of the function app
262-
echo "Getting the default host name of the function app [$function_app_name]..."
263-
function_host_name=$(azlocal functionapp show \
264-
--name "$function_app_name" \
265-
--resource-group "$resource_group_name" \
266-
--query 'defaultHostName' \
267-
--output tsv)
268-
269-
if [ -n "$function_host_name" ]; then
270-
echo "Function app default host name [$function_host_name] successfully retrieved."
271-
else
272-
echo "Error: No function app default host name found"
273-
exit 1
274-
fi
275-
276-
# Get the Docker container name
277-
echo "Finding container name with prefix [ls-$function_app_name]..."
278-
container_name=$(get_docker_container_name_by_prefix "ls-$function_app_name")
279-
280-
if [ $? -eq 0 ] && [ -n "$container_name" ]; then
281-
echo "Container [$container_name] found successfully"
282-
else
283-
echo "Failed to get container name"
284-
exit 1
285-
fi
286-
287-
# Get the container IP address
288-
echo "Getting IP address for container [$container_name]..."
289-
container_ip=$(get_docker_container_ip_address_by_name "$container_name")
290-
player_name='Leo'
291-
game_session='1'
292-
293-
if [ $? -eq 0 ] && [ -n "$container_ip" ]; then
294-
echo "IP address [$container_ip] retrieved successfully for container [$container_name]"
295-
else
296-
echo "Failed to get container IP address"
297-
exit 1
298-
fi
299-
300-
# Get the mapped host port for function app HTTP trigger (internal port 80)
301-
echo "Getting the host port mapped to internal port 80 in container [$container_name]..."
302-
host_port=$(get_docker_container_port_mapping "$container_name" "80")
303-
304-
if [ $? -eq 0 ] && [ -n "$host_port" ]; then
305-
echo "Mapped host port [$host_port] retrieved successfully for container [$container_name]"
306-
else
307-
echo "Failed to get mapped host port for container [$container_name]"
308-
exit 1
309-
fi
310-
311-
# Retrieve LocalStack proxy port
312-
proxy_port=$(curl http://localhost:4566/_localstack/proxy -s | jq '.proxy_port')
313-
314-
if [ -n "$proxy_port" ]; then
315-
# Call the GET HTTP trigger function that returns a player status in a specified game session via emulator
316-
echo "Calling HTTP trigger function to retrieve player [$player_name] status in game session [$game_session] via emulator..."
317-
curl --proxy "http://localhost:$proxy_port/" -s "http://$function_host_name/api/player/$game_session/$player_name/status" | jq
318-
319-
# Call the POST HTTP trigger function that returns the game session details via emulator
320-
echo "Calling HTTP trigger function to retrieve game session [$game_session] details via emulator..."
321-
curl --proxy "http://localhost:$proxy_port/" -s -X POST -H "Content-Type: application/json" -d "{\"gameId\": $game_session}" "http://$function_host_name/api/game/session" | jq
322-
else
323-
echo "Failed to retrieve LocalStack proxy port"
324-
fi
325-
326-
if [ -n "$container_ip" ]; then
327-
# Call the GET HTTP trigger function that returns a player status in a specified game session via the container IP address
328-
echo "Calling HTTP trigger function to retrieve player [$player_name] status in game session [$game_session] via container IP address [$container_ip]..."
329-
curl -s "http://$container_ip/api/player/$game_session/$player_name/status" | jq
330-
331-
# Call the POST HTTP trigger function that returns the game session details via the container IP address
332-
echo "Calling HTTP trigger function to retrieve game session [$game_session] details via container IP address [$container_ip]..."
333-
curl -s -X POST -H "Content-Type: application/json" -d "{\"gameId\": $game_session}" "http://$container_ip/api/game/session" | jq
334-
else
335-
echo "Failed to retrieve container IP address"
336-
fi
337-
338-
if [ -n "$host_port" ]; then
339-
# Call the GET HTTP trigger function that returns a player status in a specified game session via the host port
340-
echo "Calling HTTP trigger function to retrieve player [$player_name] status in game session [$game_session] via host port [$host_port]..."
341-
curl -s "http://localhost:$host_port/api/player/$game_session/$player_name/status" | jq
342-
343-
# Call the POST HTTP trigger function that returns the game session details via the host port
344-
echo "Calling HTTP trigger function to retrieve game session [$game_session] details via host port [$host_port]..."
345-
curl -s -X POST -H "Content-Type: application/json" -d "{\"gameId\": $game_session}" "http://localhost:$host_port/api/game/session" | jq
346-
else
347-
echo "Failed to retrieve container IP address"
348-
fi
349-
}
350-
351-
call_http_trigger_functions
352-
```
353-
354170
## Storage Contents
355171

356172
You can use [Azure Storage Explorer](https://learn.microsoft.com/en-us/azure/storage/storage-explorer/vs-azure-tools-storage-manage-with-storage-explorer) to confirm that your Azure Function app creates the expected storage entities in the emulated storage account. To do this:

samples/function-app-storage-http/dotnet/scripts/call-http-triggers.sh

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,16 @@ call_http_trigger_functions() {
138138
exit 1
139139
fi
140140

141-
# Retrieve LocalStack proxy port
142-
proxy_port=$(curl http://localhost:4566/_localstack/proxy -s | jq '.proxy_port')
143-
144-
if [ -n "$proxy_port" ]; then
145-
# Call the GET HTTP trigger function that returns a player status in a specified game session via emulator
146-
echo "Calling HTTP trigger function to retrieve player [$player_name] status in game session [$game_session] via emulator..."
147-
curl --proxy "http://localhost:$proxy_port/" -s "http://$function_host_name/api/player/$game_session/$player_name/status" | jq
141+
if [ -n "$function_host_name" ]; then
142+
# Call the GET HTTP trigger function that returns a player status in a specified game session via the function hostname
143+
echo "Calling HTTP trigger function to retrieve player [$player_name] status in game session [$game_session] via function hostname [$function_host_name]..."
144+
curl -s "http://$function_host_name/api/player/$game_session/$player_name/status" | jq
148145

149-
# Call the POST HTTP trigger function that returns the game session details via emulator
150-
echo "Calling HTTP trigger function to retrieve game session [$game_session] details via emulator..."
151-
curl --proxy "http://localhost:$proxy_port/" -s -X POST -H "Content-Type: application/json" -d "{\"gameId\": $game_session}" "http://$function_host_name/api/game/session" | jq
146+
# Call the POST HTTP trigger function that returns the game session details via the function hostname
147+
echo "Calling HTTP trigger function to retrieve game session [$game_session] details via function hostname [$function_host_name]..."
148+
curl -s -X POST -H "Content-Type: application/json" -d "{\"gameId\": $game_session}" "http://$function_host_name/api/game/session" | jq
152149
else
153-
echo "Failed to retrieve LocalStack proxy port"
150+
echo "Failed to retrieve function hostname"
154151
fi
155152

156153
if [ -n "$container_ip" ]; then
@@ -174,7 +171,7 @@ call_http_trigger_functions() {
174171
echo "Calling HTTP trigger function to retrieve game session [$game_session] details via host port [$host_port]..."
175172
curl -s -X POST -H "Content-Type: application/json" -d "{\"gameId\": $game_session}" "http://localhost:$host_port/api/game/session" | jq
176173
else
177-
echo "Failed to retrieve container IP address"
174+
echo "Failed to retrieve host port"
178175
fi
179176
}
180177

0 commit comments

Comments
 (0)