Package: arn

import "../ibm-cos-sdk-go/aws/arn"

Overview

Package arn provides a parser for interacting with Amazon Resource Names.

Type Summary collapse

Function Summary collapse

Type Details

ARN struct

ARN captures the individual fields of an Amazon Resource Name. See docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html for more information.

Structure Fields:

Partition string

The partition that the resource is in. For standard AWS regions, the partition is “aws”. If you have resources in other partitions, the partition is “aws-partitionname”. For example, the partition for resources in the China (Beijing) region is “aws-cn”.

Service string

The service namespace that identifies the AWS product (for example, Amazon S3, IAM, or Amazon RDS). For a list of namespaces, see docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#genref-aws-service-namespaces.

Region string

The region the resource resides in. Note that the ARNs for some resources do not require a region, so this component might be omitted.

AccountID string

The ID of the AWS account that owns the resource, without the hyphens. For example, 123456789012. Note that the ARNs for some resources don't require an account number, so this component might be omitted.

Resource string

The content of this part of the ARN varies by service. It often includes an indicator of the type of resource — for example, an IAM user or Amazon RDS database - followed by a slash (/) or a colon (:), followed by the resource name itself. Some services allows paths for resource names, as described in docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html#arns-paths.

Function Details

func IsARN(arn string) bool

IsARN returns whether the given string is an ARN by looking for whether the string starts with “arn:” and contains the correct number of sections delimited by colons(:).



80
81
82
// File 'aws/arn/arn.go', line 80

func IsARN(arn string) bool { return strings.HasPrefix(arn, arnPrefix) && strings.Count(arn, ":") >= arnSections-1 }

func Parse(arn string) (ARN, error)

Parse parses an ARN into its constituent parts.

Some example ARNs: arn:aws:elasticbeanstalk:us-east-1:123456789012:environment/My App/MyEnvironment arn:aws:iam::123456789012:user/David arn:aws:rds:eu-west-1:123456789012:db:mysql-db arn:aws:s3:::my_corporate_bucket/exampleobject.png



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// File 'aws/arn/arn.go', line 60

func Parse(arn string) (ARN, error) { if !strings.HasPrefix(arn, arnPrefix) { return ARN{}, errors.New(invalidPrefix) } sections := strings.SplitN(arn, arnDelimiter, arnSections) if len(sections) != arnSections { return ARN{}, errors.New(invalidSections) } return ARN{ Partition: sections[sectionPartition], Service: sections[sectionService], Region: sections[sectionRegion], AccountID: sections[sectionAccountID], Resource: sections[sectionResource], }, nil }