Class Arn

  • All Implemented Interfaces:
    ToCopyableBuilder<Arn.Builder,​Arn>

    @SdkPublicApi
    public final class Arn
    extends Object
    implements ToCopyableBuilder<Arn.Builder,​Arn>
    The Arns generated and recognized by this code are the Arns described here: https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html

    The primary supported Arn format is: arn:<partition>:<service>:<region>:<account>:<resource>

    resourceAsString() returns everything after the account section of the Arn as a single string.

    However, the following Arn formats are supported where the values are present and well formatted through resource():

     arn:<partition>:<service>:<region>:<account>:<resourcetype>/resource
     arn:<partition>:<service>:<region>:<account>:<resourcetype>/resource/qualifier
     arn:<partition>:<service>:<region>:<account>:<resourcetype>/resource:qualifier
     arn:<partition>:<service>:<region>:<account>:<resourcetype>:resource
     arn:<partition>:<service>:<region>:<account>:<resourcetype>:resource:qualifier
     
    resource() returns a ArnResource which has access to ArnResource.resourceType(), ArnResource.resource() and ArnResource.qualifier().

    To parse an Arn from a string use Arn.fromString(). To convert an Arn to it's string representation use Arn.toString().

    For instance, for a string s, containing a well-formed Arn the following should always be true:

     Arn theArn = Arn.fromString(s);
     s.equals(theArn.toString());
     
    See Also:
    ArnResource
    • Method Detail

      • partition

        public String partition()
        Returns:
        The partition that the resource is in.
      • service

        public String service()
        Returns:
        The service namespace that identifies the AWS product (for example, Amazon S3, IAM, or Amazon RDS).
      • region

        public Optional<String> region()
        Returns:
        The Region that the resource resides in.
      • accountId

        public Optional<String> accountId()
        Returns:
        The ID of the AWS account that owns the resource, without the hyphens.
      • resourceAsString

        public String resourceAsString()
        Returns:
        the resource as string
      • builder

        public static Arn.Builder builder()
        Returns:
        a builder for Arn.
      • tryFromString

        public static Optional<Arn> tryFromString​(String arn)
        Attempts to parse the given string into an Arn. If the input string is not a valid ARN, this method returns Optional.empty() instead of throwing an exception.

        When successful, the resource is accessible entirely as a string through resourceAsString(). Where correctly formatted, a parsed resource containing resource type, resource and qualifier is available through resource().

        Parameters:
        arn - A string containing an ARN to parse.
        Returns:
        An Optional containing the parsed Arn if valid, or empty if invalid.
        Throws:
        IllegalArgumentException - if the ARN contains empty partition or service fields
      • fromString

        public static Arn fromString​(String arn)
        Parses a given string into an Arn. The resource is accessible entirely as a string through resourceAsString(). Where correctly formatted, a parsed resource containing resource type, resource and qualifier is available through resource().
        Parameters:
        arn - - A string containing an Arn.
        Returns:
        Arn - A modeled Arn.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object