Module: Aws::ARNParser

Defined in:
gems/aws-sdk-core/lib/aws-sdk-core/arn_parser.rb

Class Method Summary collapse

Class Method Details

.arn?(str) ⇒ Boolean

Checks whether a String could be a ARN or not. An ARN starts with 'arn:' and has at least 6 segments separated by a colon (:).

Parameters:

  • str (String)

Returns:

  • (Boolean)


34
35
36
# File 'gems/aws-sdk-core/lib/aws-sdk-core/arn_parser.rb', line 34

def self.arn?(str)
  !str.nil? && str.start_with?('arn:') && str.scan(/:/).length >= 5
end

.parse(arn_str) ⇒ Aws::ARN

Parse a string with an ARN format into an Aws::ARN object. InvalidARNError would be raised when encountering a parsing error or the ARN object contains invalid components (nil/empty).



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'gems/aws-sdk-core/lib/aws-sdk-core/arn_parser.rb', line 11

def self.parse(arn_str)
  parts = arn_str.nil? ? [] : arn_str.split(':', 6)
  raise Aws::Errors::InvalidARNError if parts.size < 6

  # part[0] is "arn"
  arn = ARN.new(
    partition: parts[1],
    service: parts[2],
    region: parts[3],
    account_id: parts[4],
    resource: parts[5]
  )
  raise Aws::Errors::InvalidARNError unless arn.valid?

  arn
end