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"
Please note that you can parse ARNs with https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/ARNParser.html