Rパッケージhttr
を使用して、そのAPI経由でEC2サービスにアクセスしたいと考えています。しかし、私は、あなたが通常持っている「Oauth2.0」の通常の認証フォーマットには入っていないので、始める方法は少し分かりません。鍵、秘密、トークン、署名システムです。私はEC2が "シグネチャバージョン2"メソッドを使用していると思いますが、どのように動作するかは不明です。R + httrとEC2 api認証の問題
で作るクエリ要求について、私は署名のための値が必要だと思うと提供のドキュメントを見てみると
....しかし、それは
私が持っている取得する方法がわかりません以下のように、httr
を使用して、指定されたコマンドのいくつかを試してみました。私はURL文字列のパラメータのほとんどを、私と私がやりたいことを表すように適応させることができます。たとえば、AWSAccessKeyId
、ImageId
、endpoint
、Action
などです。しかし、署名値の取得についてはどこで知りませんか?与えられた例のいくつかでも
Response [http://aws.amazon.com/ec2/]
Status: 200
Content-type: text/html; charset=UTF-8
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="icon" type="image/ico" href="//d36cz9buwru1tt.cloudfront.net/favicon.ico">
<link rel="shortcut icon" type="image/ico" href="//d36cz9buwru1tt.cloudfront.net/favicon.ico">
<meta name="description" content="Amazon Elastic Compute Cloud delivers scalable, pay-as-you-go compute capacity in the cloud. " /><meta name="keywords" content="" /> ...
は、誰もが任意のEC2 APIを使用して経験し、その認証手順を持っていたし、それがBだろう持っている:私は応答を得るために
require(httr)
GET("https://ec2.amazonaws.com/
?Action=RunInstances
&ImageId=ami-60a54009
&MaxCount=3
&MinCount=1
&Placement.AvailabilityZone=us-east-1b
&Monitoring.Enabled=true
&AWSAccessKeyId=0GS7553JW74RRM612K02EXAMPLE
&Version=2012-10-01
&Expires=2010-10-10T12:00:00Z
&Signature=lBP67vCvGlDMBQ1dofZxg8E8SUEXAMPLE
&SignatureVersion=2
&SignatureMethod=HmacSHA256")
私が選んだAMI(それにRや他の関連パッケージがロードされている)を使ってLinuxインスタンスをセットアップして実行できるようにRを使い、そのインスタンスでいくつかのRコマンドを実行して出力を戻すのに十分なほど簡単です。
はそのは本当に私のSessionInfoに関連しているが、念のためにここにあると思いませんか:
sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] httr_0.2
loaded via a namespace (and not attached):
[1] digest_0.5.2 plyr_1.7.1 RCurl_1.95-1.1 stringr_0.6.1 tools_2.15.1
EDIT:
ので、@により示唆されるようにドキュメントを追跡するための更なる試みでハドレーこれは私が試したし、得たものである...イムは間違っている上の任意のより多くの有用なヒントを大幅に...いただければ幸いです。
require(httr)
aws.key <- "xxxxxxx"
aws.secret <- "xxxxxxxxxxxx"
verb <- "GET"
zone <- "ec2.amazonaws.com"
func <- "DescribeImages"
ami.number <- "ami-xxxxxxxxx"
params <- list(paste0("ImageId.1=",ami.number),
"Version=2012-10-01",
"Expires=2012-11-20T12%3A00%3A00Z")
# adding in method and key parameters for creation of string to sign
orig.len.params <- length(params)
params.w.method.key <- params
params.w.method.key[[orig.len.params+1]] <- "SignatureVersion=2"
params.w.method.key[[orig.len.params+2]] <- "SignatureMethod=HmacSHA1"
params.w.method.key[[orig.len.params+3]] <- paste0("AWSAccessKeyId=",aws.key)
# String to sign (s2s)
s2s <- paste(c(paste0(verb,"\n",zone,"\n","/\n","AWSAccessKeyId=",aws.key),paste0("Action=",func),paste(sort(unlist(params.w.method.key)),collapse="&")),collapse="&")
# Signature(sig)
sig <- hmac_sha1(aws.secret, s2s)
# adding in signature, method and key parameters for signed request url generation
params.w.sig.method.key <- params
params.w.sig.method.key[[orig.len.params+1]] <- paste0("Signature=",sig)
params.w.sig.method.key[[orig.len.params+2]] <- "SignatureVersion=2"
params.w.sig.method.key[[orig.len.params+3]] <- "SignatureMethod=HmacSHA1"
params.w.sig.method.key[[orig.len.params+4]] <- paste0("AWSAccessKeyId=",aws.key)
# Signed request (sr)
sr <- paste(c(paste0("https://",zone,paste0("?Action=",func)),paste(unlist(params.w.sig.method.key),collapse="&")),collapse="&")
# GET signed request
GET(sr)
私は応答を得ます:
Response [https://ec2.amazonaws.com?Action=DescribeImages&ImageId.1=[ami.number.from.before]&Version=2012-10-01&Expires=2012-11-20T12%3A00%3A00Z&Signature=[sig.value.from.before]&SignatureVersion=2&SignatureMethod=HmacSHA1&AWSAccessKeyId=[aws.key.from.before]/]
Status: 401
Content-type:
<?xml version="1.0" encoding="UTF-8"?>
<Response><Errors><Error><Code>AuthFailure</Code><Message>AWS was not able to validate the provided access credentials</Message></Error></Errors><RequestID>5e10fb0b-f304-4677-9c64-98b4537c659a</RequestID></Response>
署名を生成するための基本的なアルゴリズムはhttp://docs.amazonwebservices.com/AWSEC2/latest/UserGuide/using-query-api.html#query-authenticationに配置されています'hmac'はステップ3のために機能します。 – hadley
ありがとう...私はそれを見ましたが、それが意味することを理解していなかったと確信していませんでした。 –
、または私の編集内容が間違っている場所を潜在的に参照してください。私は近いと思う... –