public class Arn extends Object
The primary supported ARN format is: arn:<partition>:<service>:<region>:<account>:<resource>
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());
getResourceAsString()
returns everything after the account section of the ARN
as a single string.
You can also retrieve the resource with the different resource parts using getResource()
.
This method returns a ArnResource
which has access to ArnResource.getResourceType()
,
ArnResource.getResource()
and ArnResource.getQualifier()
.
The following ARN formats are supported when parsing resources:
arn:<partition>:<service>:<region>:<account>:resource
arn:<partition>:<service>:<region>:<account>:<resourcetype>/resource
arn:<partition>:<service>:<region>:<account>:<resourcetype>/resource:qualifier
arn:<partition>:<service>:<region>:<account>:<resourcetype>:resource
arn:<partition>:<service>:<region>:<account>:<resourcetype>:resource:qualifier
Some services use parent- and subresources which follow the format
'sub-resource-type/parent-resource/sub-resource'. In this case, the whole expression 'parent-resource/sub-resource'
will be returned as the resource-id. An ARN using this pattern would be
arn:<partition>:<service>:<region>:<account>:<resourcetype>/parent-resource/sub-resource
which has
a resource type and a resource but no qualifier.
Note:
Parsing permutations of any ARN formats not covered in tests or described as supported in documentation are at the
user's own risk, as these use cases may change in the future.
Modifier and Type | Class and Description |
---|---|
static class |
Arn.Builder |
Modifier and Type | Method and Description |
---|---|
static Arn.Builder |
builder() |
boolean |
equals(Object o) |
static Arn |
fromString(String arn)
Parses a given string into an
Arn . |
String |
getAccountId() |
String |
getPartition() |
String |
getRegion() |
ArnResource |
getResource() |
String |
getResourceAsString() |
String |
getService() |
int |
hashCode() |
Arn.Builder |
toBuilder() |
String |
toString() |
public String getPartition()
public String getService()
public String getRegion()
public String getAccountId()
public ArnResource getResource()
public String getResourceAsString()
public Arn.Builder toBuilder()
public static Arn.Builder builder()
public static Arn fromString(String arn)
Arn
. The resource is accessible entirely as a
string through getResourceAsString()
. Where correctly formatted, a parsed
resource containing resource type, resource and qualifier is available through
getResource()
.arn
- - A string containing an ARN.Arn
- A modeled ARN.Copyright © 2023. All rights reserved.