Class: Aws::ARN

Inherits:
Object
  • Object
show all
Defined in:
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)


39
40
41
42
43
44
45
# File 'lib/aws-sdk-core/arn.rb', line 39

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)


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

def 
  @account_id
end

#partitionString (readonly)

Returns:

  • (String)


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

def partition
  @partition
end

#regionString (readonly)

Returns:

  • (String)


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

def region
  @region
end

#resourceString (readonly)

Returns:

  • (String)


60
61
62
# File 'lib/aws-sdk-core/arn.rb', line 60

def resource
  @resource
end

#serviceString (readonly)

Returns:

  • (String)


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

def service
  @service
end

Instance Method Details

#as_json(_options = nil) ⇒ Hash

Return the ARN as JSON

Returns:

  • (Hash)


95
96
97
98
99
100
101
102
103
# File 'lib/aws-sdk-core/arn.rb', line 95

def as_json(_options = nil)
  {
    'partition' => @partition,
    'service' => @service,
    'region' => @region,
    'accountId' => @account_id,
    'resource' => @resource
  }
end

#to_hHash

Return the ARN as a hash

Returns:

  • (Hash)


82
83
84
85
86
87
88
89
90
# File 'lib/aws-sdk-core/arn.rb', line 82

def to_h
  {
    partition: @partition,
    service: @service,
    region: @region,
    account_id: @account_id,
    resource: @resource
  }
end

#to_sString

Return the ARN format in string

Returns:

  • (String)


75
76
77
# File 'lib/aws-sdk-core/arn.rb', line 75

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)


66
67
68
69
70
# File 'lib/aws-sdk-core/arn.rb', line 66

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