尝试在 AWS S3 上使用客户端 API 初始化 Datomic Cloud 时出现“无法读取密钥文件”错误

`Unable to read keyfile` error when trying to initialize Datomic Cloud with Client API on AWS S3

我正在测试使用 IntelliJ IDE 设置 Datomic Cloud。我正在关注来自 Datomic 的客户端 API 啧啧,但在初始化客户端时卡住了。

来自 API 客户的规范在此处,图在此处,在使用 Datomic Cloud 的步骤下。

所以 tut 说要像这样初始化一个客户端:

(require '[datomic.client.api :as d])
(def cfg {:server-type :ion
      :region "<your AWS Region>" ;; e.g. us-east-1
      :system "<system name>"
      :creds-profile "<your_aws_profile_if_not_using_the_default>"
      :endpoint "<your endpoint>"})

他们说如果不使用默认配置文件,则要包括 AWS 配置文件。据我所知,我使用的是默认值——我不属于 AWS 中的组织。

这是我的 tutorial.core 命名空间中的(部分编辑的)代码,我正在尝试初始化 Datomic:

(ns tutorial.core   
(:gen-class))
(require '[datomic.client.api :as d])
(def cfg {:server-type :cloud
  :region "us-east-2"
  :system "roam"
  :endpoint "https://API_ID.execute-api.us-east-2.amazonaws.com"
  })
(def client (d/client cfg))
(d/create-database client {:db-name "blocks"})
(d/connect client {:db-name "blocks"})

但是,我从 Clojure 收到错误消息:Forbidden to read keyfile at s3://URL/roam/datomic/access/admin/.keys. Make sure that your endpoint is correct, and that your ambient AWS credentials allow you to GetObject on the keyfile.

我需要某种凭证吗?是否还有其他原因导致此错误?我从我的 CloudFormation Datomic 堆栈中的 ClientApiGatewayEndpoint 获得了端点 URL。

如果我需要提供更多信息,请告诉我!谢谢。 我尝试了这里提到的解决方案,但它没有用,我在网上的任何地方都找不到这个问题的答案。

当您从您的计算机初始化客户端时,数据库正在尝试使用您传递的任何 AWS 凭证访问 S3 以读取一些配置文件。您提到您使用的是默认配置文件,因此很可能您有一个 ~/.aws/credentials 文件,其中包含 [default] 条目以及访问密钥和密钥。

错误:

Forbidden to read keyfile at s3://URL/roam/datomic/access/admin/.keys. Make sure that your endpoint is correct, and that your ambient AWS credentials allow you to GetObject on the keyfile.

表示datomic库无法从S3读取文件。出现这种情况的原因有很多。使用 AWS cli

尝试 运行 以下操作
aws s3 cp s3://URL/roam/datomic/access/admin/.keys .

我假设它会失败,这意味着您的默认配置文件没有必要的权限从 S3 读取此资源,因此您从 datomic.要修复它,您需要为您的 AWS 用户 IAM 角色添加必要的权限(密钥文件上的 GetObject,如错误消息所建议的那样)。

您可以尝试的一件事是创建个人资料。在你的 ~/.aws/credentials

[datomic]
aws_access_key_id = your-access-key
aws_secret_access_key = your-secret-key
region = us-east-2

然后将您的 cfg 映射更改为:

(def cfg {:server-type :cloud
  :region "us-east-2"
  :system "roam"
  :creds-profile "datomic"
  :endpoint "https://API_ID.execute-api.us-east-2.amazonaws.com"
  }