Hello开发者社区,
我正在使用AWS Cloudsearch(API版本:2011-02-01)并尝试从生活在heroku上的应用程序上传和搜索,这意味着我需要一个带有静态IP的代理,以便我可以将其列入白名单,但是我遇到了问题...
我正在使用名为Proximo的Heroku插件。这是Heroku使用RestClient进行设置的代码示例:
require "rest-client"
RestClient.proxy = ENV["PROXIMO_URL"] if ENV["PROXIMO_URL"]
res = RestClient.get("http://api.someservice.com/endpoint")
puts "status code", res.code
puts "headers", res.headers
我正在使用使用Faraday发出请求的aws_cloud_search gem,并且我很难通过我的补丁从CloudSearch获得正确的响应
# aws_cloud_search.rb
def self.create_connection(url, aws_access_key_id=nil, aws_secret_access_key=nil)
options = ENV['PROXIMO_URL'] ? { proxy: ENV['PROXIMO_URL'] } : {}
connection = Faraday.new url, options do |builder|
builder.use AWSCloudSearch::HttpCodeResponseMiddleware
builder.use FaradayMiddleware::EncodeJson
builder.use FaradayMiddleware::ParseJson
builder.adapter Faraday.default_adapter
builder.proxy ENV['PROXIMO_URL'] if ENV['PROXIMO_URL']
end
connection.headers['User-Agent'] = "AWSCloudSearch-Ruby-Client/#{VERSION}"
connection
end
我尝试了许多补丁工作的组合here(以及其他地方)无济于事。当我使用端口80(正如他们建议的那样)设置具有Proximo提供的IP地址的代理时,我得到以下内容:
Faraday::Error::ParsingError: 757: unexpected token at 'invalid'
from /app/vendor/bundle/ruby/2.0.0/gems/json-1.6.8/lib/json/common.rb:149:in `parse'
from /app/vendor/bundle/ruby/2.0.0/gems/json-1.6.8/lib/json/common.rb:149:in `parse'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/response/parse_json.rb:11:in `block in <class:ParseJson>'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/response_middleware.rb:48:in `call'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/response_middleware.rb:48:in `parse'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/response_middleware.rb:39:in `process_response'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/response_middleware.rb:32:in `block in call'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday-0.8.1/lib/faraday/response.rb:63:in `on_complete'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/response_middleware.rb:30:in `call'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/request/encode_json.rb:23:in `call'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday-0.8.1/lib/faraday/response.rb:8:in `call'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday-0.8.1/lib/faraday/connection.rb:226:in `run_request'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday-0.8.1/lib/faraday/connection.rb:99:in `post'
from /app/vendor/bundle/ruby/2.0.0/bundler/gems/aws_cloud_search-0d5b94169466/lib/aws_cloud_search/cloud_search.rb:18:in `documents_batch'
from (irb):9
from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.19/lib/rails/commands/console.rb:47:in `start'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.19/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.19/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'irb(main):010:0> ENV['PROXIMO_URL']
=&GT; "http://nn.nnn.nn.nn:80" (i've obscured my ip address)
我认为这意味着被解析的实际密钥是'无效',我在搜索和文档上得到这个(我不使用ssl)。 (我在没有代理的情况下获得带有403 Forbidden的html)。我试图打印出响应体,但我认为错误发生在我甚至可以将其打印出来之前(与403一样)。
我没有尝试过任何明显的问题或者我的方法有问题吗?
由于
答案 0 :(得分:0)
aws-sdk-core
gem现在支持CloudSearch域API(Search,Suggest,UploadDocuments)。您应该能够安装gem并使用代理配置客户端:
require 'aws-sdk-core'
client = Aws::CloudSearchDomain::Client.new(
endpoint:'http://...',
http_proxy: 'http://...')
客户端API参考可以在这里找到: http://docs.aws.amazon.com/sdkforruby/api/Aws/CloudSearchDomain/Client.html