You can use this code to reliably parse an AWS ARN and get its various sections.
Paste this class into your library, or put arn_parse.rb
into your project's lib
folder and require it. Then you can feed it an ARN and get back an object:
require_relative 'lib/arn_parse.rb'
my_arn = Arn.parse 'arn:aws:sns:*:123456789012:my_corporate_topic' => #<Arn:0x00007f91550a6e80 @partition="aws", @service="sns", @region="*", @account="123456789012", @resource="my_corporate_topic">
my_arn.service => "sns"
I hope you find it useful! Beware that I did find some arns later that didn't... reliably fit into this parsing scheme. You can end up with
arn.resource
strings that contain colons.I don't know whether or not it's always valid, but I was pretty convinced when I wrote the class :)