Amazon Web Services: NoCredentialsError: Unable to locate credentials

Amazon Web Services: NoCredentialsError: Unable to locate credentials

我正在使用亚马逊网络服务客户端。我使用 makefile 来构建我的 lambda 项目并将其上传到 aws lambda。我在 windows 机器上使用 powershell 调用 make.

我尝试使用以下行删除我的 lambda 函数

AWS_PATH = /cygdrive/c/Users/TestBox/AppData/Roaming/Python/Scripts/aws
AWS_WIN_PATH = $(shell cygpath -aw ${AWS_PATH})
AWS_REGION = eu-west-2

lambda_delete:
    $(AWS_WIN_PATH) lambda delete-function --function-name LambdaTest --region $(AWS_REGION) --debug

我收到这个错误..

NoCredentialsError:无法找到凭据 无法找到凭据。您可以通过 运行 "aws configure".

配置凭据

运行 aws configure list 打印出有效的默认配置文件。

我认为问题是因为我在 windows 机器上使用由 cygwin 安装的 gnu make。使用 powershell 调用 make.

所以凭证的路径看起来像这样 "cygdrive/c/users/testbox/.aws/credentials" 而不是 "c:\users\testbox.aws\credentials",当 ~/.aws/credentials 由 aws 评估时。我认为:)

我对 aws 本身的路径有同样的问题,不得不使用 $(shell cygpath -aw ${AWS_PATH}) 将其转换为路径 windows python 可以使用。

有没有办法将凭据直接传递给 lambda 删除函数或通过文件路径间接传递?我似乎想不出办法,因为搜索凭据的代码在 botocore 内部。

有没有你知道的解决方法?

备选方案,考虑使用AWS SAM templates

使用 AWS SAM 模板通过 CloudFormation 部署您的 Lambda 函数和 AWS 资源。

  • 编辑您的 SAM 模板并定义您的 AWS 资源。例如,为您的代码定义 Lambda functions/path。
  • aws cloudformation package 将您的本地代码打包并上传到 S3。
  • aws cloudformation deploy 使用 S3 上的更新代码配置和更新 AWS 资源。

这将在 CMD/Powershell 中工作,没有 make 麻烦。您还将受益于将资源版本化为代码,并且无需担心在 make 文件中跟踪或添加新的 AWS API。

更复杂的无服务器框架供参考: