1

我正在尝试使用 ruby​​ 实现亚马逊 SNS。我想创建一个主题,删除一个主题,订阅一个主题,发布到一个主题。这些都包含在以下代码中。

#!/usr/bin/env ruby
require 'rubygems'
require 'aws-sdk'
AWS.config(:access_key_id => 'BT62W53Q', :secret_access_key => '0Edwg')
@sns=AWS::SNS.new

#D requirements
alpha = @sns.topics.create('CSC470Test-Alpha')

@sns.topics.create('CSC470Test-Beta')
temp=gets
@sns.topics.each do |topic|
  puts topic.name
  if(topic.name=='CSC470Test-Beta')
    topic.delete
  end
end
puts
puts 'Beta now deleted.'
puts
@sns.topics.each do |topic|
  puts topic.name
end
puts
temp=gets
puts
#C requirements
@sns.topics.each do |topic|
  if(topic.name=='CSC470Test-Alpha')
    subbed1=false
    subbed2=false
    subbed3=false
    topic.subscriptions.each do |sub|
      if(sub.endpoint=='sn@aine.com')
        subbed1=true;
      end
      if(sub.endpoint=='pran@aine.com')
        subbed2=true;
      end
      if(sub.endpoint=='http://cloud.comtor.org/csc470logger/logger')
        subbed3=true;
      end
    end
    if(!subbed1)
      puts 'Subscribed sika.'
      topic.subscribe('sn@aine.com')
    end
    if(!subbed2)
      puts 'Subscribed prka'
      topic.subscribe('pran@aine.com', :json => true)
    end
    if(!subbed3)
      puts 'Subscribed comtor site.'
      topic.subscribe('http://cloud.comtor.org/csc470logger/logger')
    end
  end
end
temp=gets
puts 'Topics with info:'
@sns.topics.each do |topic|
  puts
  puts 'Arn'
  puts topic.arn
  puts 'Owner'
  puts topic.owner
  puts 'Policy'
  puts topic.policy
  puts 'Name'
  puts topic.display_name
  puts 'Confirmed Subscriptions:'
  puts topic.subscriptions.
    select{ |s| s.arn != 'PendingConfirmation' }.
    map(&:endpoint)
# if(subs.confirmation_authenticated?)
  # puts 'Arn: ' + subs.arn
  # puts 'Endpoint: ' + subs.endpoint
  # puts 'Protocol: ' + subs.protocol
 # end
end
puts
temp=gets
@sns.subscriptions.each do |subs|
  puts "SubscriptionARN: #{ subs.arn} "
  puts "TopicARN: #{subs.topic_arn} "
  puts "Owner: #{subs.owner_id} "
  puts "Delivery Policy: #{ subs.delivery_policy_json} "
  end

在 Rails 控制台中运行此代码时。我收到此错误

C:/ProgramData/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/aws-sdk-1.8.5/l
ib/aws/core/client.rb:339:in `return_or_raise': The request signature we calcula
ted does not match the signature you provided. Check your AWS Secret Access Key
and signing method. Consult the service documentation for details. (AWS::SNS::Er
rors::SignatureDoesNotMatch)
        from C:/ProgramData/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/aw
s-sdk-1.8.5/lib/aws/core/client.rb:440:in `client_request'
        from (eval):3:in `create_topic'
        from C:/ProgramData/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/aw
s-sdk-1.8.5/lib/aws/sns/topic_collection.rb:24:in `create'
4

0 回答 0