我正在使用 AWS CLI v2 创建配置文件并通过计算机上的 sso 登录 AWS。然后,我尝试使用 paws 包通过 R 访问存储在 AWS Athena 上的数据库中的数据。
我认为我的配置文件设置正确,但是当我尝试在 Athena 中列出数据目录时,收到一条错误消息:“加载 SSO 令牌时出错:myprof 的令牌不存在”
在 AWS CLI v2(在 Windows 上)中,我运行
aws configure sso
并按照有关配置 SSO 的 AWS 文档中所述设置我的配置文件。
完成此操作后,我的配置文件如下所示:
[profile myprof]
sso_session = myprof
sso_account_id = 123456789012
sso_role_name = AWSAdministratorAccess
region = us-east-2
output = json
[sso-session myprof]
sso_start_url = https://mycompany.awsapps.com/start#/
sso_region = us-east-2
sso_registration_scopes = sso:account:access
在此过程中,我的网络浏览器打开,我确认命令行中显示的代码。在 R 中,我有此代码,如 paws 文档中有关
使用 AWS Single Sign On 和 连接到 Athena 中所述:
library(paws)
Sys.setenv(AWS_PROFILE = 'myprof',AWS_REGION = 'us-east-2')
svc = athena()
svc$list_data_catalogs(options("paws.log_level" = 3L))
当我运行这个时,我得到这个结果:
INFO [2023-11-10 08:20:45.468]: Unable to locate credentials file
Error: Error loading SSO Token: Token for myprof does not exist
根据我从 paws 文档中可以理解的,如果我使用 sso,我不需要凭据文件(与 这个问题 不同)。想知道我是否做错了什么,或者是否需要检查某个设置才能使其正常工作?不确定问题是否出在我正在做的事情上,或者是爪子上还是 IAM 设置上。
aws sso login --profile myprof
library(paws)
client <- athena(config(credentials(profile = "myprof")))
client$list_data_catalogs()
注意:您不需要设置环境变量,因为您已经设置了 .aws/config
文件。您只需在 athena 连接中设置配置文件即可。或者,您可以使用
noctua 并构建在 paws
之上来提供 DBI 接口。
library(DBI)
library(noctua)
con <- dbConnect(noctua::athena(), profile_name = "myprof", s3_staging_dir = "s3://mybucket/athena-query")
dbListTables(con)
我希望这有帮助