Azure function Time Trigger sdk python



我有一个完全工作的python脚本,它连接到一个密钥库,从中检索一些秘密,并使用这些秘密执行一些备份。不用说,这段代码在局部运行得很好:

import datetime
import logging
import azure.functions as func
from typing import Container
from azure.cosmosdb.table.tableservice import TableService,ListGenerator
from azure.storage.blob import BlobClient, BlobServiceClient, ContainerClient
from azure.storage.blob import ResourceTypes, AccountSasPermissions
from azure.storage.blob import generate_account_sas    
from datetime import date, timedelta
from azure.keyvault.secrets import SecretClient
from azure.identity import DefaultAzureCredential
def main(mytimer: func.TimerRequest) -> None:
utc_timestamp = datetime.datetime.utcnow().replace(
tzinfo=datetime.timezone.utc).isoformat()
if mytimer.past_due:
logging.info('The timer is past due!')
logging.info('Python timer trigger function ran at %s', utc_timestamp)
today = str(date.today().strftime("%Y%m%d"))
print(today)
keyvault_name = f'url'
KeyVaultName = "name"
credential = DefaultAzureCredential()
client_keyvault = SecretClient(vault_url=keyvault_name, credential=credential)

脚本获取正确的凭证并开始移动容器作为备份。

我所面临的问题是在将此逻辑移动到azure功能后开始的。当代码触发时,我得到以下错误

Result: Failure Exception: ClientAuthenticationError: DefaultAzureCredential failed to retrieve a token from the included credentials. Attempted credentials: EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured. ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable, no managed identity endpoint found. SharedTokenCacheCredential: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache. VisualStudioCodeCredential: Failed to get Azure user details from Visual Studio Code. AzureCliCredential: Azure CLI not found on path AzurePowerShellCredential: PowerShell is not installed Stack

我知道azure函数正在寻找凭据进行身份验证,但我认为这种身份验证(在azure函数中)在我被身份验证时自动发生。

请帮助解决和理解这个问题?

如果你需要更多的信息,请不要犹豫,问

问题解决了,我必须激活ManageIdentity

相关内容

  • 没有找到相关文章

最新更新