我正在构建一个rails应用程序,我使用dynamoDB作为数据库(使用dynamoid)。在运行测试时,出现以下错误:
Aws::Errors::MissingCredentialsError:unable to sign request without credentials set
因为测试是在本地dynamoDB中运行的,所以我对这个错误消息有点困惑。是我的测试没有在本地数据库中运行,而是试图访问远程数据库吗?
可以对本地dynamodb使用下面的配置。当您提供本地主机端点时,dynamodb直接使用端点,而不是从区域派生端点。
Aws.config.update({
region: 'us-west-2',
credentials: Aws::Credentials.new('akid', 'secret'),
endpoint:'http://localhost:8000'
})
该区域用于构造SSL端点。如果需要的话连接到非标准端点时,可以指定:端点选择。
在我的例子中,我只是缺少设置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"