0
votes

I'm trying to deploy Azure Functions in already created App Service in Azure portal.

Using sls deploy CLI for deploying my Azure function, but while deploying the functions sls is trying to create new resource group for which I don't have access.

Following is the output of sls deploy command:

$ sls deploy
Serverless: Removing .serverless directory
Serverless: Parsing Azure Functions Bindings.json...
Serverless: Building binding for function: admin event: httpTrigger
Serverless: Parsing Azure Functions Bindings.json...
Serverless: Building binding for function: image event: httpTrigger
Serverless: Parsing Azure Functions Bindings.json...
Serverless: Building binding for function: report event: httpTrigger
Serverless: Parsing Azure Functions Bindings.json...
Serverless: Building binding for function: gaims event: httpTrigger
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Logging into Azure
Serverless: Using subscription ID: <SUBSCRIPTION_ID>
Serverless: Creating resource group: <ALREADY_CREATED_RESOURCE_GROUP_NAME>

  Error --------------------------------------------------

  Error: The client '<USER_NAME>' with object id '<OBJECT_ID>' does not have authorization to perform action 
     'Microsoft.Resources/subscriptions/resourcegroups/write' over scope 
    '/subscriptions/SUBSCRIPTION_ID/resourcegroups/ALREADY_CREATED_RESOURCE_GROUP_NAME' or the scope is invalid. 
    If access was recently granted, please refresh your credentials.
      at new RestError (C:\Users\analysis-node\node_modules\@azure\ms-rest-js\lib\restError.ts:18:5)
      at C:\Users\analysis-node\node_modules\@azure\ms-rest-js\lib\policies\deserializationPolicy.ts:117:27
      at process._tickCallback (internal/process/next_tick.js:68:7)

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information ---------------------------
     Operating System:          win32
     Node Version:              10.20.1
     Framework Version:         1.71.1
     Plugin Version:            3.6.12
     SDK Version:               2.3.0
     Components Version:        2.30.11

In serverless.yml, I've also specified the resourceGroup parameter. Here is the gist of serverless.yml

provider:
  stage: dev
  name: azure
  region: East US 2
  runtime: nodejs10.x
  resourceGroup: <ALREADY_CREATED_RESOURCE_GROUP_NAME>
  subscriptionId: <SUBSCRIPTION_ID>

Is there any way to set resource group in serverless cli which can be used while deploying the functions?

1
From the error message, looks like the service principal / user trying to execute this doesn't have permission to create resources, isn't it? Probably should be a contributor. there is a similar question here [stackoverflow.com/a/37689720/5344880] with accepted answer. hope it helpsGuru Pasupathy
Not looking to create a resource group. Only want to deploy my functions under an App Service.Parag Jadhav
@ParagJadhav I agree with Guru, you should check the subscription permission of the service principal or user you used to deploy the function.Tony Ju
@TonyJu I have a contributor access to the function that I'm sure of. I can even deploy the function in the current app service if I generate a new project template using Azure Function extension in VS Code. Please let me know if you want me to update the question with more granularityParag Jadhav

1 Answers

0
votes

I was able to deploy the Azure functions by breaking down the deployment in two parts

  1. Package the project using serverless.

    sls package
    
  2. Deploy the packaged zip file using Azure CLI.

    az functionapp deployment source config-zip -g {RESOURCE_GROUP} -n {APP_SERVICE_NAME} --src .serverless/project-zip.zip
    

Hope this helps someone who is facing the same issue.

Edit:

Looks like this issue might get resolved in upcoming releases.

Link: https://github.com/serverless/serverless-azure-functions/issues/469