Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过R查询AWS定价API_R_Amazon Web Services - Fatal编程技术网

通过R查询AWS定价API

通过R查询AWS定价API,r,amazon-web-services,R,Amazon Web Services,我试图通过R查询AWS定价端点,但得到403错误 我四处寻找了在R中运行AWS端点的一般示例,但确实没有找到太多。有什么想法吗 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&quo

我试图通过R查询AWS定价端点,但得到403错误

我四处寻找了在R中运行AWS端点的一般示例,但确实没有找到太多。有什么想法吗

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 = "apigateway.us-east-1.amazonaws.com",
             `x-amz-date` = d_timestamp)

params <- signature_v4_auth(
  datetime = d_timestamp,
  region = "us-east-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://api.pricing.us-east-1.amazonaws.com",
         query = params)
库(aws.签名)
图书馆(httr)
#验证参数和安装请求URL

当前您还可以使用
paws
包查询AWS价目表服务API。提供从R中访问完整AWS服务套件的功能,类似于Python的官方AWS SDK boto3向Python用户提供的功能

在下面的示例中,我使用定价客户端获取Amazon SageMaker当前可用的所有位置。我使用
purr
包来解析响应。 我将我的AWS凭证(AWS\u访问权\u密钥\u ID、AWS\u机密\u访问权\u密钥)存储在
.Renviron
中,这就是您在下面的代码中看不到它们的原因

library(paws)
library(purrr)

# Create pricing client
pricing_client <- pricing()

# Fetch metadata information of the SageMaker service
sm_metadata <- pricing_client$describe_services(
   ServiceCode = "AmazonSageMaker")

str(sm_metadata)
#> List of 3
#>  $ Services     :List of 1
#>   ..$ :List of 2
#>   .. ..$ ServiceCode   : chr "AmazonSageMaker"
#>   .. ..$ AttributeNames: chr [1:34] "productFamily" "automaticLabel" "volumeType" "memory" ...
#>  $ FormatVersion: chr "aws_v1"
#>  $ NextToken    : chr(0) 

# Store available SageMaker service attribute names in a vector
sm_attributes <- sm_metadata %>% 
  pluck("Services", 1,  "AttributeNames")

tail(sm_attributes)
#> [1] "groupDescription" "currentGeneration" "integratingService" "location" "processorArchitecture" "operation" 

# Fetch all locations where the SageMaker service is available
sm_locations <-  pricing_client$get_attribute_values("AmazonSageMaker", "location") %>% 
  .[["AttributeValues"]] %>% 
  map_chr(function(x) x[["Value"]])

sm_locations
#> [1] "AWS GovCloud (US-West)"    "Any"                       "Asia Pacific (Hong Kong)" 
#> [4] "Asia Pacific (Mumbai)"     "Asia Pacific (Seoul)"      "Asia Pacific (Singapore)" 
#> [7] "Asia Pacific (Sydney)"     "Asia Pacific (Tokyo)"      "Canada (Central)"         
#> [10] "EU (Frankfurt)"            "EU (Ireland)"              "EU (London)"              
#> [13] "EU (Paris)"                "EU (Stockholm)"            "Middle East (Bahrain)"    
#> [16] "South America (Sao Paulo)" "US East (N. Virginia)"     "US East (Ohio)"           
#> [19] "US West (N. California)"   "US West (Oregon)" 
库(paws)
图书馆(purrr)
#创建定价客户机
定价\u客户端$服务:1个列表
#>..$:2人名单
#>   .. ..$ 服务代码:chr“亚马逊管理者”
#>   .. ..$ AttributeName:chr[1:34]“productFamily”“automaticLabel”“volumeType”“memory”。。。
#>$FormatVersion:chr“aws_v1”
#>$NextToken:chr(0)
#将可用的SageMaker服务属性名称存储在向量中
sm_属性%
拔毛(“服务”,1,“属性名称”)
尾部(sm_属性)
#>[1]“groupDescription”“currentGeneration”“integratingService”“位置”“processorArchitecture”“操作”
#获取SageMaker服务可用的所有位置
sm_位置%
[[“属性值”]]%>%
映射_chr(函数(x)x[[“值”]]
sm_位置
#>[1]“AWS GovCloud(美国西部)”任何“亚太地区(香港)”
#>[4]“亚太(孟买)”“亚太(首尔)”“亚太(新加坡)”
#>[7]“亚太(悉尼)”“亚太(东京)”“加拿大(中部)”
#>[10]“欧盟(法兰克福)”“欧盟(爱尔兰)”“欧盟(伦敦)”
#>[13]“欧盟(巴黎)”“欧盟(斯德哥尔摩)”“中东(巴林)”
#>[16]“南美洲(圣保罗)”“美国东部(北弗吉尼亚)”“美国东部(俄亥俄州)”
#>[19]“美国西部(北加利福尼亚)”“美国西部(俄勒冈州)”

请确定,当您运行它时,您是否有key和secret的实际值,而不仅仅是asterix?403错误向我表明您的凭据不好。@alex_danielssen-是的,我有密钥和机密的实际值。