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

使用Serverless Framework部署AWS Lambda时遇权限错误求助

解决Serverless Framework AWS部署时的权限与凭证匹配问题

Hey there! Let's work through this issue together—first, the biggest red flag here is that the error mentions the lifeline-s3 user, but you configured the serverless user as your default. That means Serverless Framework isn't using the credentials you think it is, so let's break this down step by step:

1. 确认当前Serverless使用的凭证身份

First, let's verify which AWS user Serverless is actually authenticating with:

  • Run this command in your project directory:
    serverless info --verbose
    
    Look for the ARN field in the output—if it shows arn:aws:iam::6644331164204:user/lifeline-s3, that confirms the tool is picking up credentials for this user instead of your serverless user.

2. 排查凭证来源不匹配的原因

AWS credentials follow a strict priority order, so let's check the most likely culprits:

  • 环境变量冲突: 检查你的shell中是否设置了AWS_ACCESS_KEY_ID和AWS_SECRET_ACCESS_KEY环境变量,它们可能指向lifeline-s3的密钥。运行以下命令验证:
    echo $AWS_ACCESS_KEY_ID
    echo $AWS_SECRET_ACCESS_KEY
    
    如果输出对应lifeline-s3的密钥,它们会覆盖你设置的默认profile凭证。
  • 项目本地.env文件: 查看numpy-test项目目录下是否有.env文件,如果里面配置了AWS凭证变量,会优先于全局设置生效。
  • Serverless.yml指定的profile: 打开你的serverless.yml,检查是否存在provider.aws.profile字段,它可能指向了一个使用lifeline-s3凭证的profile。
  • 全局凭证文件: 打开~/.aws/credentials,确认[default] profile使用的是serverless用户的密钥,如果有其他profile被意外加载,也会导致这个问题。

3. 修复凭证不匹配并重新验证权限

找到lifeline-s3凭证的来源后,进行修正:

  • 如果是环境变量的问题,执行以下命令清除它们:
    unset AWS_ACCESS_KEY_ID
    unset AWS_SECRET_ACCESS_KEY
    
  • 如果是.env文件的冲突,更新或删除其中的AWS凭证行。
  • 如果serverless.yml指定了错误的profile,将其改为default(或你为serverless用户创建的profile),或者直接删除该字段以使用默认凭证。
  • 重新配置默认凭证确保无误:
    serverless config credentials --provider aws --key YOUR_SERVERLESS_USER_ACCESS_KEY --secret YOUR_SERVERLESS_USER_SECRET_KEY --profile default
    

修正凭证问题后,如果仍遇到权限错误:

  • 登录AWS IAM控制台,检查serverless用户的已附加策略:确保AdministratorAccess和你自定义的CloudFormation策略都已正确附加,且无语法错误。
  • 等待策略生效:IAM策略的传播可能需要1-5分钟,如果你刚添加策略,稍等片刻再重试。
  • 重新执行部署命令:
    serverless deploy
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 09:00:08