You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Azure Serverless应用时出现AWS凭据缺失错误求助

问题描述

按照Azure Functions Serverless插件的官方步骤创建应用时,遇到两个问题:

  1. 执行命令 sls create -t azure-python -p <appName> 时,系统提示「Configuration file not found in directory "/Users//z-serverless"」
  2. 手动创建包含Azure配置的serverless.yml后,执行任何Serverless命令都会弹出错误:
✖ AWS credentials missing or invalid. Run "serverless" to set up AWS credentials, or learn more in our docs: http://slss.io/aws-creds-setup.

明明全程配置的是Azure相关参数,却被要求提供AWS凭据,对此感到困惑。

附手动创建的serverless.yml内容:

# "org" ensures this Service is used with the correct Serverless Framework Access Key.
org: t
# "app" enables Serverless Framework Dashboard features and sharing them with other Services.
app: z-serverless
service: azure-serverless
useDotenv: true

provider:
  name: azure
  region: westus
  runtime: python3.8 # python3.7 or python3.8 also available
  os: linux  # linux is the only operating system available for python
  subscriptionId: <subscriptionId>

plugins: # look for additional plugins in the community plugins repo: https://github.com/serverless/plugins
  - serverless-azure-functions
  - serverless-dotenv-plugin

# you can add packaging information here
package:
  patterns:
    - '!env/**'
    - '!.env/**'
    - '!local.settings.json'
    - '!.vscode/**'
    - '!__pycache__/**'
    - '!node_modules/**'
    - '!.python_packages/**'
    - '!.funcignore'
    - '!package.json'
    - '!package-lock.json'
    - '!.gitignore'
    - '!.git/**'
  exclude:
    - local.settings.json
    - .vscode/**
解决方案
  1. 调整sls create执行顺序
    sls create是用来从官方模板生成完整项目结构的命令,包括适配Azure的serverless.yml。正确操作应该是先创建空目录并进入,再执行初始化命令,而非提前手动创建配置文件:
mkdir z-serverless && cd z-serverless
sls create -t azure-python -p z-serverless

这样生成的配置文件会自动绑定Azure provider,避免手动配置可能出现的冲突。

  1. 确认Azure插件已安装
    如果坚持手动配置serverless.yml,必须确保serverless-azure-functions插件已正确安装。插件未安装时,Serverless Framework会默认使用AWS作为provider,从而触发凭据错误:
  • 本地项目安装(推荐):
npm install serverless-azure-functions --save-dev
  • 全局安装:
npm install -g serverless-azure-functions
  1. 排查全局配置干扰
    检查用户根目录下的~/.serverless/config.json文件,如果其中包含AWS相关的默认配置,可能会覆盖项目的provider设置。可以临时重命名该文件测试,或者确保项目的serverless.yml中provider.name明确设置为azure(你的配置已满足,但需保证插件生效)。

  2. 验证配置文件合法性
    执行以下命令检查serverless.yml是否存在语法错误:

sls config validate

如果配置文件存在格式问题,也可能导致框架无法正确识别Azure provider。

内容的提问来源于stack exchange,提问作者Raman Saini

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 13:12:22