我需要在R中对AWS API进行身份验证。我尝试使用aws.signature包执行相同的操作,我收到403响应,错误缺少身份验证令牌。似乎我错过了一些必要的参数。寻求协助调试以下代码或在R中验证AWS API的方法。
# To create aws signature for authentication for the rest API call
library(aws.signature)
library(httr)
# validate arguments and setup request URL
current <- Sys.time()
d_timestamp <- format(current, "%Y%m%dT%H%M%SZ", tz = "UTC")
hdrs <- list(`Content-Type` = "application/x-www-form-urlencoded",
Host = "jteti5wnje.execute-api.eu-central-1.amazonaws.com",
`x-amz-date` = d_timestamp)
params <- signature_v4_auth(
datetime = d_timestamp,
region = "eu-central-1",
service = "execute-api",
verb = "GET",
action = "iMetaAPI",
query_args = list(),
canonical_headers = hdrs,
request_body = "json",
key = "***************",
secret = "*****************",
session_token = NULL,
query = FALSE,
algorithm = "AWS4-HMAC-SHA256",
verbose = TRUE)
a <- GET("https://jteti5wnje.execute-api.eu-central-1.amazonaws.com/iMetaAPI",
query = params)
rawToChar(a$content)
答案 0 :(得分:1)
一些事情:
request_body
需要成为真正的身体。您正在GET()
进行NULL
或""
。signature_v4_auth()
的回复是一个列表,但您不需要其所有元素 - 可能只是hds$Authorization <- params$SignatureHeader
元素。您获得的实际错误是因为您尚未通过标头。您需要使用GET()
之类的标题将标题传递给do.call(add_headers, hdrs)
,以便您可以执行以下操作:
a <- GET("https://jteti5wnje.execute-api.eu-central-1.amazonaws.com/iMetaAPI", do.call(add_headers, headers))
这可能会奏效,或者你至少会得到更多信息。