pub struct Arn { /* private fields */ }
Expand description
An Amazon Resource Name (ARN) representing an exact resource.
This is used to represent a known resource, such as an S3 bucket, EC2 instance, assumed role instance, etc. This is not used to represent resource statements in the IAM Aspen policy language, which may contain wildcards.
Arn objects are immutable.
Implementations§
Source§impl Arn
impl Arn
Sourcepub fn new(
partition: &str,
service: &str,
region: &str,
account_id: &str,
resource: &str,
) -> Result<Self, ArnError>
pub fn new( partition: &str, service: &str, region: &str, account_id: &str, resource: &str, ) -> Result<Self, ArnError>
Create a new ARN from the specified components.
partition
- The partition the resource is in (required). This is usuallyaws
,aws-cn
, oraws-us-gov
for actual AWS resources, but may be any string meeting the rules specified in validate_partition for non-AWS resources.service
- The service the resource belongs to (required). This is a service name likeec2
ors3
. Non-AWS resources must conform to the naming rules specified in validate_service.region
- The region the resource is in (optional). If the resource is regional (and may other regions may have the resources with the same name), this is the region name. If the resource is global, this is empty. This is usually a region name likeus-east-1
orus-west-2
, but may be any string meeting the rules specified in validate_region.account_id
- The account ID the resource belongs to (optional). This is the 12-digit account ID or the stringaws
for certain AWS-owned resources. Some resources (such as S3 buckets and objects) do not need the account ID (the bucket name is globally unique within a partition), so this may be empty.resource
- The resource name (required). This is the name of the resource. The formatting is service-specific, but must be a valid UTF-8 string.
§Errors
- If the partition is invalid, ArnError::InvalidPartition is returned.
- If the service is invalid, ArnError::InvalidService is returned.
- If the region is invalid, ArnError::InvalidRegion is returned.
- If the account ID is invalid, ArnError::InvalidAccountId is returned.
Sourcepub unsafe fn new_unchecked(
partition: &str,
service: &str,
region: &str,
account_id: &str,
resource: &str,
) -> Self
pub unsafe fn new_unchecked( partition: &str, service: &str, region: &str, account_id: &str, resource: &str, ) -> Self
Create a new ARN from the specified components, bypassing any validation.
§Safety
The following constraints must be met:
partition
- Must meet the rules specified in validate_partition.service
- Must meet the rules specified in validate_service.region
- Must be empty or meet the rules specified in validate_region.account_id
- Must be empty, a 12 ASCII digit account ID, or the stringaws
.resource
- A valid UTF-8 string.
Sourcepub fn account_id(&self) -> &str
pub fn account_id(&self) -> &str
Retrieve the account ID the resource belongs to.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Arn
impl<'de> Deserialize<'de> for Arn
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl FromStr for Arn
Parse a string into an Arn.
impl FromStr for Arn
Parse a string into an Arn.
Source§fn from_str(s: &str) -> Result<Self, ArnError>
fn from_str(s: &str) -> Result<Self, ArnError>
Parse an ARN from a string.
§Errors
- If the ARN is not composed of 6 colon-separated components, ArnError::InvalidArn is returned.
- If the ARN does not start with
arn:
, ArnError::InvalidArn is returned. - If the partition is invalid, ArnError::InvalidPartition is returned.
- If the service is invalid, ArnError::InvalidService is returned.
- If the region is invalid, ArnError::InvalidRegion is returned.
- If the account ID is invalid, ArnError::InvalidAccountId is returned.
Source§impl Ord for Arn
Orders ARNs by partition, service, region, account ID, and resource.
impl Ord for Arn
Orders ARNs by partition, service, region, account ID, and resource.
Source§fn cmp(&self, other: &Self) -> Ordering
fn cmp(&self, other: &Self) -> Ordering
Returns the relative ordering between this and another ARN.
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Arn
Orders ARNs by partition, service, region, account ID, and resource.
impl PartialOrd for Arn
Orders ARNs by partition, service, region, account ID, and resource.