繁体   English   中英

Azure function 时间触发器 sdk python

[英]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 function 后,我面临的问题开始了。当代码触发时,我收到以下错误

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 function 正在寻找要进行身份验证的凭据,但我认为此身份验证(在 azure 函数中)会在我通过身份验证时自动发生。

请问有什么帮助解决和理解这个问题吗?

如果您需要更多信息,请随时询问

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM