An Azure service that provides a hybrid, multi-cloud management platform for APIs.
Linking Function to APIM with Bicep
I got APIM and Function app, that are linked manually as a reference.
Now I'm trying to reproduce the same with Bicep.
I googled up a bunch of samples, but none of them are actually create the same result as doing it manually. They generally query function keys and add policy attaching them to the URL etc.
In the UI one cannot see the Function app and APIM connected in any way.
What I want to achieve:
in the API definition see the function as the backend.
In the function app see it connected to the API management, as that:
What I'm able to achieve at the moment:
In the APIM to register the function as HTTP endpoint.
@description('Create API Management')
resource apiManagementService 'Microsoft.ApiManagement/service@2024-05-01' = {
// ....
@description('Register the backend for the function')
resource functionBackend 'backends@2022-08-01' = {
name: 'function-app-backend'
properties: {
protocol: 'http'
description: 'Function App'
url: 'https://${functionApp.properties.defaultHostName}'
resourceId: uri(environment().resourceManager, functionApp.id)
}
}
@description('Create APIM API for function app')
resource functionApi 'apis@2022-08-01' = {
name: 'function-api'
properties: {
path: 'webhooks'
apiType: 'http'
displayName: functionApp.name
subscriptionRequired: false // for testing let it be anonymous at the start
protocols: ['https']
serviceUrl: 'https://${functionApp.properties.defaultHostName}/api'
}
@description('Link function app as backend - create policy')
resource functionAppBackendPolicy 'policies@2022-08-01' = {
name: 'policy'
properties: {
value: replace('''<policies>
<inbound>
<base />
<set-backend-service id="functionapp-inbound-policy" backend-id="_backendname_" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>''', '_backendname_', functionBackend .name)
format: 'xml'
}
}
// sample endpoint
resource get_Ping 'operations@2022-08-01' = {
name: 'get-ping'
properties: {
displayName: 'ping'
method: 'GET'
urlTemplate: '/ping'
}
}
This will give me 401 Unauthorised, because APIm and Function are not connected. It simply routes. If I add function keys, it will start working most likely, but it is not how it's done if via UI.
If I open my function APP, there will be no API Management registered with it.
So far examples tend to practice in number of modules and extras, but none found actually simply connects function and apim as if it was done via UI.
Please help.
Azure API Management
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
1 answer
Sort by: Most helpful
-
Deleted
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more