Class: Aws::ARN

Inherits:
Object
  • Object
show all
Defined in:
gems/aws-sdk-core/lib/aws-sdk-core/arn.rb

Overview

Create and provide access to components of Amazon Resource Names (ARN).

You can create an ARN and access it's components like the following:

arn = Aws::ARN.new( partition: 'aws', service: 's3', region: 'us-west-2', account_id: '12345678910', resource: 'foo/bar' ) # => #<Aws::ARN ...>

arn.to_s # => "arn:aws:s3:us-west-2:12345678910:foo/bar"

arn.partition # => 'aws' arn.service # => 's3' arn.resource # => foo/bar

# Note: parser available for parsing resource details @see Aws::ARNParser#parse_resource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ARN

Returns a new instance of ARN.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :partition (String)
  • :service (String)
  • :region (String)
  • :account_id (String)
  • :resource (String)


37
38
39
40
41
42
43
# File 'gems/aws-sdk-core/lib/aws-sdk-core/arn.rb', line 37

def initialize(options = {})
  @partition = options[:partition]
  @service = options[:service]
  @region = options[:region]
  @account_id = options[:account_id]
  @resource = options[:resource]
end

Instance Attribute Details

#account_idString (readonly)

Returns:

  • (String)


55
56
57
# File 'gems/aws-sdk-core/lib/aws-sdk-core/arn.rb', line 55

def 
  @account_id
end

#partitionString (readonly)

Returns:

  • (String)


46
47
48
# File 'gems/aws-sdk-core/lib/aws-sdk-core/arn.rb', line 46

def partition
  @partition
end

#regionString (readonly)

Returns:

  • (String)


52
53
54
# File 'gems/aws-sdk-core/lib/aws-sdk-core/arn.rb', line 52

def region
  @region
end

#resourceString (readonly)

Returns:

  • (String)


58
59
60
# File 'gems/aws-sdk-core/lib/aws-sdk-core/arn.rb', line 58

def resource
  @resource
end

#serviceString (readonly)

Returns:

  • (String)


49
50
51
# File 'gems/aws-sdk-core/lib/aws-sdk-core/arn.rb', line 49

def service
  @service
end

Instance Method Details

#to_sString

Return the ARN format in string

Returns:

  • (String)


73
74
75
# File 'gems/aws-sdk-core/lib/aws-sdk-core/arn.rb', line 73

def to_s
  "arn:#{partition}:#{service}:#{region}:#{}:#{resource}"
end

#valid?Boolean

Validates ARN contains non-empty required components. Region and account_id can be optional.

Returns:

  • (Boolean)


64
65
66
67
68
# File 'gems/aws-sdk-core/lib/aws-sdk-core/arn.rb', line 64

def valid?
  !partition.nil? && !partition.empty? &&
    !service.nil? && !service.empty? &&
    !resource.nil? && !resource.empty?
end