class Aws::ARN

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

@see docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#genref-arns

Attributes

account_id[R]

@return [String]

partition[R]

@return [String]

region[R]

@return [String]

resource[R]

@return [String]

service[R]

@return [String]

Public Class Methods

new(options = {}) click to toggle source

@param [Hash] options @option options [String] :partition @option options [String] :service @option options [String] :region @option options [String] :account_id @option options [String] :resource

# 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

Public Instance Methods

to_h() click to toggle source

Return the ARN as a hash

@return [Hash]

# 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_s() click to toggle source

Return the ARN format in string

@return [String]

# File lib/aws-sdk-core/arn.rb, line 75
def to_s
  "arn:#{partition}:#{service}:#{region}:#{account_id}:#{resource}"
end
valid?() click to toggle source

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

@return [Boolean]

# File lib/aws-sdk-core/arn.rb, line 66
def valid?
  !partition.nil? && !partition.empty? &&
    !service.nil? && !service.empty? &&
    !resource.nil? && !resource.empty?
end