ruby Aws::Errors::MissingCredentialsError:无法在未设置凭据的情况下对请求进行签名

lqfhib0f  于 2023-05-06  发布在  Ruby
关注(0)|答案(2)|浏览(191)

我正在构建一个Rails应用程序,我使用dynamoDB作为数据库(使用dynamoid)。当我运行测试时,我得到以下错误:
Aws::Errors::MissingCredentialsError:unable to sign request without credentials set
由于测试是在本地dynamoDB中运行的,所以我对这个错误消息有点困惑。是不是我的测试没有在本地数据库中运行,而他们正在尝试访问远程数据库?

vltsax25

vltsax251#

您可以使用下面的本地dynamodb配置。当您给予localhost端点时,dynamodb直接使用该端点,而不是从region派生端点。

Aws.config.update({
  region: 'us-west-2',
  credentials: Aws::Credentials.new('akid', 'secret'),
  endpoint:'http://localhost:8000'
})

该区域用于构造SSL端点。如果需要连接到非标准端点,可以指定:endpoint选项。

llycmphe

llycmphe2#

在我的例子中,我只是缺少设置2个env变量,如官方文档中所述:https://github.com/aws/aws-sdk-ruby#configuration
在我设置这些之后,一切都工作了:

# Consumed by AWS Cognito under the hood. Required. A.k.a. client ID.
AWS_ACCESS_KEY_ID = "xxxxxxxxxxxxxxxxxx"

# Consumed by AWS Cognito under the hood. Required. A.k.a. client secret.
AWS_SECRET_ACCESS_KEY = "xxxxxxxxxxxxxxxxxxx"

相关问题