У меня есть функция azure, которая была разработана для автоматизации взаимодействия с API Management.
Итак, после Http Trigger он создавал пользователя управления api. уровень, и все работало нормально - я его тестировал и все.
![enter image description here](https://i.stack.imgur.com/gb89h.png)
После перехода с уровня разработчика на уровень потребления я теперь получаю следующую ошибку во время выполнения функции:
[6/19/2020 2:37:28 AM] ERROR: New-AzApiManagementUser :
[6/19/2020 2:37:28 AM] Error Code: MethodNotAllowedInPricingTier
[6/19/2020 2:37:28 AM] Error Message: Method not allowed in this pricing tier
[6/19/2020 2:37:28 AM] Request Id: d6112a6a-c7ab-4648-85f6-74518c2a1351
[6/19/2020 2:37:28 AM]
[6/19/2020 2:37:28 AM] At C:\Users\*******\AzureProjects\course_api_mgmt\course_api_mgmt\run.ps1:48 char:13
[6/19/2020 2:37:28 AM] + $user = New-AzApiManagementUser -Context $context -FirstName $use ...
[6/19/2020 2:37:28 AM] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[6/19/2020 2:37:28 AM] + CategoryInfo : CloseError: (Microsoft.Azure.Man\u2026ase.ExecuteCmdlet():ErrorResponseException) [New-AzApiManagementUser], Exception
[6/19/2020 2:37:28 AM] + FullyQualifiedErrorId : Operation returned an invalid status code 'BadRequest',Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.NewAzureApiManagementUser
[6/19/2020 2:37:28 AM]
[6/19/2020 2:37:28 AM] Script stack trace:
[6/19/2020 2:37:28 AM] at <ScriptBlock>, C:\Users\*******\AzureProjects\course_api_mgmt\course_api_mgmt\run.ps1: line 48
[6/19/2020 2:37:28 AM]
[6/19/2020 2:37:28 AM] System.Exception:
[6/19/2020 2:37:28 AM] Error Code: MethodNotAllowedInPricingTier
[6/19/2020 2:37:28 AM] Error Message: Method not allowed in this pricing tier
[6/19/2020 2:37:28 AM] Request Id: d6112a6a-c7ab-4648-85f6-74518c2a1351
[6/19/2020 2:37:28 AM]
[6/19/2020 2:37:28 AM]
[6/19/2020 2:37:28 AM]
[6/19/2020 2:37:28 AM] Result: ERROR: New-AzApiManagementUser :
[6/19/2020 2:37:28 AM] Error Code: MethodNotAllowedInPricingTier
[6/19/2020 2:37:28 AM] Error Message: Method not allowed in this pricing tier
[6/19/2020 2:37:28 AM] Request Id: d6112a6a-c7ab-4648-85f6-74518c2a1351
[6/19/2020 2:37:28 AM]
[6/19/2020 2:37:28 AM] At C:\Users\*******\AzureProjects\course_api_mgmt\course_api_mgmt\run.ps1:48 char:13
[6/19/2020 2:37:28 AM] + $user = New-AzApiManagementUser -Context $context -FirstName $use ...
[6/19/2020 2:37:28 AM] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[6/19/2020 2:37:28 AM] + CategoryInfo : CloseError: (Microsoft.Azure.Man\u2026ase.ExecuteCmdlet():ErrorResponseException) [New-AzApiManagementUser], Exception
[6/19/2020 2:37:28 AM] + FullyQualifiedErrorId : Operation returned an invalid status code 'BadRequest',Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.NewAzureApiManagementUser
[6/19/2020 2:37:28 AM]
[6/19/2020 2:37:28 AM] Script stack trace:
[6/19/2020 2:37:28 AM] at <ScriptBlock>, C:\Users\*******\AzureProjects\course_api_mgmt\course_api_mgmt\run.ps1: line 48
[6/19/2020 2:37:28 AM]
[6/19/2020 2:37:28 AM] System.Exception:
[6/19/2020 2:37:28 AM] Error Code: MethodNotAllowedInPricingTier
[6/19/2020 2:37:28 AM] Error Message: Method not allowed in this pricing tier
[6/19/2020 2:37:28 AM] Request Id: d6112a6a-c7ab-4648-85f6-74518c2a1351
[6/19/2020 2:37:28 AM]
[6/19/2020 2:37:28 AM]
[6/19/2020 2:37:28 AM]
Exception:
[6/19/2020 2:37:28 AM] Error Code: MethodNotAllowedInPricingTier
[6/19/2020 2:37:28 AM] Error Message: Method not allowed in this pricing tier
[6/19/2020 2:37:28 AM] Request Id: d6112a6a-c7ab-4648-85f6-74518c2a1351
[6/19/2020 2:37:28 AM]
Stack: .
[6/19/2020 2:37:29 AM] INFORMATION:
[6/19/2020 2:37:29 AM] ERROR: New-AzApiManagementSubscription : Cannot validate argument on parameter 'UserId'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
[6/19/2020 2:37:29 AM] At C:\Users\*******\AzureProjects\course_api_mgmt\course_api_mgmt\run.ps1:61 char:71
[6/19/2020 2:37:29 AM] + ... -AzApiManagementSubscription -Context $context -UserId $user.UserId `
[6/19/2020 2:37:29 AM] + ~~~~~~~~~~~~
[6/19/2020 2:37:29 AM] + CategoryInfo : InvalidData: (:) [New-AzApiManagementSubscription], ParameterBindingValidationException
[6/19/2020 2:37:29 AM] + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.NewAzureApiManagementSubscription
[6/19/2020 2:37:29 AM]
[6/19/2020 2:37:29 AM] Script stack trace:
[6/19/2020 2:37:29 AM] at <ScriptBlock>, C:\Users\*******\AzureProjects\course_api_mgmt\course_api_mgmt\run.ps1: line 61
[6/19/2020 2:37:29 AM]
[6/19/2020 2:37:29 AM] System.Management.Automation.ParameterBindingValidationException: Cannot validate argument on parameter 'UserId'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
[6/19/2020 2:37:29 AM] at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CmdletParameterBinderController.BindParameter(CommandParameterInternal argument, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CmdletParameterBinderController.BindParameter(UInt32 parameterSets, CommandParameterInternal argument, MergedCompiledCommandParameter parameter, ParameterBindingFlags
flags)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CmdletParameterBinderController.BindParameters(UInt32 parameterSets, Collection`1 arguments)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 arguments)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CommandProcessor.BindCommandLineParameters()
[6/19/2020 2:37:29 AM] at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
[6/19/2020 2:37:29 AM] at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
[6/19/2020 2:37:29 AM] at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
[6/19/2020 2:37:29 AM] --- End of stack trace from previous location where exception was thrown ---
[6/19/2020 2:37:29 AM] at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
[6/19/2020 2:37:29 AM] at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
[6/19/2020 2:37:29 AM] at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
[6/19/2020 2:37:29 AM] at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
[6/19/2020 2:37:29 AM] at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
[6/19/2020 2:37:29 AM]
[6/19/2020 2:37:29 AM] Inner exception: System.Management.Automation.ValidationMetadataException: The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
[6/19/2020 2:37:29 AM] at System.Management.Automation.ValidateNotNullOrEmptyAttribute.Validate(Object arguments, EngineIntrinsics engineIntrinsics)
[6/19/2020 2:37:29 AM] at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
[6/19/2020 2:37:29 AM]
[6/19/2020 2:37:29 AM]
[6/19/2020 2:37:29 AM] Result: ERROR: New-AzApiManagementSubscription : Cannot validate argument on parameter 'UserId'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
[6/19/2020 2:37:29 AM] At C:\Users\*******\AzureProjects\course_api_mgmt\course_api_mgmt\run.ps1:61 char:71
[6/19/2020 2:37:29 AM] + ... -AzApiManagementSubscription -Context $context -UserId $user.UserId `
[6/19/2020 2:37:29 AM] + ~~~~~~~~~~~~
[6/19/2020 2:37:29 AM] + CategoryInfo : InvalidData: (:) [New-AzApiManagementSubscription], ParameterBindingValidationException
[6/19/2020 2:37:29 AM] + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Commands.NewAzureApiManagementSubscription
[6/19/2020 2:37:29 AM]
[6/19/2020 2:37:29 AM] Script stack trace:
[6/19/2020 2:37:29 AM] at <ScriptBlock>, C:\Users\Aubrey\AzureProjects\course_api_mgmt\course_api_mgmt\run.ps1: line 61
[6/19/2020 2:37:29 AM]
[6/19/2020 2:37:29 AM] System.Management.Automation.ParameterBindingValidationException: Cannot validate argument on parameter 'UserId'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
[6/19/2020 2:37:29 AM] at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CmdletParameterBinderController.BindParameter(CommandParameterInternal argument, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CmdletParameterBinderController.BindParameter(UInt32 parameterSets, CommandParameterInternal argument, MergedCompiledCommandParameter parameter, ParameterBindingFlags
flags)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CmdletParameterBinderController.BindParameters(UInt32 parameterSets, Collection`1 arguments)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 arguments)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CommandProcessor.BindCommandLineParameters()
[6/19/2020 2:37:29 AM] at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
[6/19/2020 2:37:29 AM] at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
[6/19/2020 2:37:29 AM] at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
[6/19/2020 2:37:29 AM] --- End of stack trace from previous location where exception was thrown ---
[6/19/2020 2:37:29 AM] at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
[6/19/2020 2:37:29 AM] at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
[6/19/2020 2:37:29 AM] at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
[6/19/2020 2:37:29 AM] at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
[6/19/2020 2:37:29 AM] at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
[6/19/2020 2:37:29 AM]
[6/19/2020 2:37:29 AM] Inner exception: System.Management.Automation.ValidationMetadataException: The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
[6/19/2020 2:37:29 AM] at System.Management.Automation.ValidateNotNullOrEmptyAttribute.Validate(Object arguments, EngineIntrinsics engineIntrinsics)
[6/19/2020 2:37:29 AM] at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
[6/19/2020 2:37:29 AM]
[6/19/2020 2:37:29 AM]
Exception: Cannot validate argument on parameter 'UserId'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
Stack: at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBindingFlags flags)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CmdletParameterBinderController.BindParameter(CommandParameterInternal argument, MergedCompiledCommandParameter parameter, ParameterBindingFlags flags)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CmdletParameterBinderController.BindParameter(UInt32 parameterSets, CommandParameterInternal argument, MergedCompiledCommandParameter parameter, ParameterBindingFlags
flags)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CmdletParameterBinderController.BindParameters(UInt32 parameterSets, Collection`1 arguments)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 arguments)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CommandProcessor.BindCommandLineParameters()
[6/19/2020 2:37:29 AM] at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues)
[6/19/2020 2:37:29 AM] at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
[6/19/2020 2:37:29 AM] at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
[6/19/2020 2:37:29 AM] at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
[6/19/2020 2:37:29 AM] --- End of stack trace from previous location where exception was thrown ---
[6/19/2020 2:37:29 AM] at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
[6/19/2020 2:37:29 AM] at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElementAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
[6/19/2020 2:37:29 AM] at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
[6/19/2020 2:37:29 AM] at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
[6/19/2020 2:37:29 AM] at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame).
[6/19/2020 2:37:29 AM] OUTPUT:
[6/19/2020 2:37:30 AM] Executed 'Functions.course_api_mgmt' (Failed, Id=e500bbdd-bac7-49cc-9076-5ff11c8d440c)
[6/19/2020 2:37:30 AM] System.Private.CoreLib: Exception while executing function: Functions.course_api_mgmt. System.Private.CoreLib: Result: Failure
Exception: Object reference not set to an instance of an object.
Stack: at Microsoft.Azure.Functions.PowerShellWorker.Utility.TypeExtensions.DeriveContentType(HttpResponseContext httpResponseContext, RpcHttp rpcHttp) in C:\projects\azure-functions-powershell-worker\src\Utility\TypeExtensions.cs:line 196
[6/19/2020 2:37:30 AM] at Microsoft.Azure.Functions.PowerShellWorker.Utility.TypeExtensions.ToRpcHttp(HttpResponseContext httpResponseContext) in C:\projects\azure-functions-powershell-worker\src\Utility\TypeExtensions.cs:line 188
[6/19/2020 2:37:30 AM] at Microsoft.Azure.Functions.PowerShellWorker.Utility.TypeExtensions.ToTypedData(Object value) in C:\projects\azure-functions-powershell-worker\src\Utility\TypeExtensions.cs:line 242
[6/19/2020 2:37:30 AM] at Microsoft.Azure.Functions.PowerShellWorker.RequestProcessor.BindOutputFromResult(InvocationResponse response, AzFunctionInfo functionInfo, Hashtable results) in C:\projects\azure-functions-powershell-worker\src\RequestProcessor.cs:line 466
[6/19/2020 2:37:30 AM] at Microsoft.Azure.Functions.PowerShellWorker.RequestProcessor.ProcessInvocationRequestImpl(StreamingMessage request, AzFunctionInfo functionInfo, PowerShellManager psManager, FunctionInvocationPerformanceStopwatch stopwatch) in C:\projects\azure-functions-powershell-worker\src\RequestProcessor.cs:line 306.
Я не заметил этого, когда смотрел на различия между уровнями, когда решил переключиться, но сообщение об ошибке кажется довольно простым. Может ли кто-нибудь подтвердить, что я буквально не могу запустить команду New-AzApiManagementUser
в контексте экземпляра управления API уровня потребления?
А если нет, есть ли способ автоматизировать создание пользователей управления API на уровне потребления?