Specify region when publishing to an SNS topic using AWS SDK for Ruby

ljcundiff picture ljcundiff · Jan 17, 2014 · Viewed 7.1k times · Source

I am publishing a message to and AWS SNS topic from a Rails 3 application using the AWS SDK for Ruby as below:

sns = AWS::SNS.new
topic = sns.topics['arn:aws:sns:eu-west-1:55555555555:my_topic']
topic.publish("MESSAGE", :subject => "SUBJECT")

When I publish to a topic in "us-east-1" it works as expected, but publishing to a topic in region "eu-west-1" does not work throwing:

AWS::SNS::Errors::InvalidParameter - Invalid parameter: TopicArn:

With the AWS SDK for Java set the region when creating the client object. Is there a similar way to set the region with the AWS SDK for Ruby?

Answer

bennie j picture bennie j · Jan 20, 2014

Yes, in your AWS config which you can either pass in with your config intializer script

:region => 'eu-west-1'

Or create it in a file with your accesskey etc and pass the whole file in when newing up your api client

sns = AWS::SNS.new configFile