{"id":548,"date":"2023-08-31T01:43:00","date_gmt":"2023-08-31T01:43:00","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=548"},"modified":"2023-08-31T01:43:00","modified_gmt":"2023-08-31T01:43:00","slug":"aws-arn-guide","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=548","title":{"rendered":"AWS ARN Explained: Amazon Resource Name Beginners Guide"},"content":{"rendered":"<p>In this blog, I discuss concepts, tips, and tricks related to AWS ARN. I will also explain how to create ARN URLs for specific AWS resources.<\/p><p>I have also added all the important links to AWS resources to quickly build the ARN you need.<\/p><h2 id=\"what-is-arn-in-aws\">What is ARN in AWS?<\/h2><p><strong>Amazon Resource Name (ARN)<\/strong> are unique identifiers assigned to individual AWS resources. It can be an ec2 instance, <a href=\"https:\/\/devopscube.com\/automate-ebs-snapshot-creation-deletion\/\" rel=\"noreferrer noopener\">EBS Volumes<\/a>, S3 bucket, load balancers, VPCs, route tables, etc.<\/p><p>An ARN looks like the following for an ec2 instance.<\/p><pre><code>arn:aws:ec2:us-east-1:4575734578134:instance\/i-054dsfg34gdsfg38<\/code><\/pre><h2 id=\"why-are-arn-important\">Why are ARN Important?<\/h2><p>ARN play a crucial role in IAM policies. You will end up using ARN if you follow the standard <a href=\"https:\/\/devopscube.com\/things-to-do-for-securing-aws-account\/\" rel=\"noreferrer noopener\">security best practices for IAM<\/a> roles and policies.<\/p><p>ARN have the following key use cases.<\/p><ol><li>They are used in IAM policies for granting restricted granular access to resources. One example is to allow a specific IAM user to access only specific ec2 instances.<\/li><li>It can be used in <a href=\"https:\/\/devopscube.com\/infrastructure-as-code-configuration-management\/\">Infrastructure as Code<\/a> scripts and API calls to refer to other resources. You can see a practical example in the <a href=\"https:\/\/devopscube.com\/terraform-iam-role\/\">Terraform IAM role creation<\/a> blog.<\/li><\/ol><p>If you did not understand the above points, don&#8217;t worry, we will look at those with practical examples in the following topics.<\/p><h2 id=\"aws-arn-format\">AWS ARN format<\/h2><p>In most cases, you can build the ARN URL yourself following the below format.<\/p><pre><code>arn:aws:service:region:account-id:resource-id\narn:aws:service:region:account-id:resource-type\/resource-id\narn:aws:service:region:account-id:resource-type:resource-id<\/code><\/pre><p>In the above formats, towards the end, you can see the difference in the formats which changes as per the resource types.<\/p><p>Here are the arn examples for all three formats.<\/p><p><strong>S3 ARN Example:<\/strong> S3 has a flat hierarchy of buckets and associated objects. Here is what an S3 ARN would look like<\/p><pre><code>arn:aws:s3:::devopscube-bucket<\/code><\/pre><p><strong>EC2 ARN Example: <\/strong>ec2 service has sub resource-types like <code>image, security groups<\/code> etc. The following example uses the instance <code>resource-type<\/code>.<\/p><pre><code>arn:aws:ec2:us-east-1:4575734578134:instance\/i-054dsfg34gdsfg38<\/code><\/pre><p><strong>Lambda ARN Example:<\/strong> Lambda functions can have multiple versions. Here the version is the qualifier. To have arn of the specific Lambda version, you need to mention the version number at the last as shown below<\/p><pre><code>arn:aws:lambda:us-east-1:4575734578134:function:api-fucntion:1<\/code><\/pre><h2 id=\"components-of-an-arn\">Components of an ARN<\/h2><p>ARN structure consists of several components and the arn structures used in AWS are given below<\/p><pre><code>arn:partition:service:region:account-id:resource-id\narn:partition:service:region:account-id:resource-type\/resource-id\narn:partition:service:region:account-id:resource-type:resource-id<\/code><\/pre><p>The components are listed below in detail<\/p>\n<!--kg-card-begin: html-->\n<ol class=\"wp-block-list\">\n<li><strong>ARN<\/strong> &#8211; Every arn begins with this prefix.<\/li>\n\n\n<li><strong>Partition<\/strong> &#8211; This specifies the region in which the AWS account is in, <strong>AWS<\/strong> is the partion for most resources. <br>There are also other particion, <strong>aws-us-gov<\/strong> for US government resources and <strong>aws-cn<\/strong> for resources in China.<\/li>\n\n\n<li><strong>Service<\/strong> &#8211; The service specifies the AWS service to which the resource is belong to. For example it will be <strong>arn:aws:ec2:<\/strong> for EC2 and <strong>arn:aws:s3: for S3<\/strong>.<\/li>\n\n\n<li><strong>Region<\/strong> &#8211; This component specifies the region in which the resource is located. <br>It is only available for regional resources like <strong>EC2<\/strong> and will not be available for global resources like <strong>IAM<\/strong>.<\/li>\n\n\n<li><!--kg-card-begin: html--><span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\"><strong>Account ID<\/strong>&nbsp;&#8211; Specifies the account ID of the AWS account in which the resource is in.<\/span><!--kg-card-end: html--><\/li>\n\n\n<li><strong>Resource Type<\/strong> &#8211; This component is not available for all resources, it is only available for resources which are inside a service with multiple resources.<br>For example, EC2 has multiple resources like Instance, AMI, etc,.. Resource Type is used for these resources.<\/li>\n\n\n<li><!--kg-card-begin: html--><span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\"><strong>Resource ID<\/strong>&nbsp;&#8211; This is a unique identity for resources within the AWS account.<\/span><!--kg-card-end: html--><\/li>\n<\/ol>\n<!--kg-card-end: html-->\n<h2 id=\"how-to-get-the-arn-of-aws-resources\">How to get the ARN of AWS resources?<\/h2><p>If you are getting started with AWS, you may find it difficult to put together the correct arn URL for a resource.<\/p><p>You can find the syntax for ARN for all the <a href=\"https:\/\/docs.aws.amazon.com\/IAM\/latest\/UserGuide\/reference_policies_actions-resources-contextkeys.html?ref=devopscube.com\" rel=\"noreferrer noopener\">AWS services here<\/a>.<\/p><p>For example, in that AWS document, if you <a href=\"https:\/\/docs.aws.amazon.com\/IAM\/latest\/UserGuide\/list_amazonec2.html?ref=devopscube.com\" rel=\"noreferrer noopener\">go ec2 resource<\/a> from the list, and scroll down to the &#8220;Resource Types Defined by Amazon EC2&#8221; section, you will find the reference for all the sub rsource types for ec2 as shown below.<\/p><figure class=\"kg-card kg-image-card kg-card-hascaption\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/resource-type-min-1.png\" class=\"kg-image\" alt=\"aws arn reference document\" loading=\"lazy\" width=\"687\" height=\"489\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/resource-type-min-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/resource-type-min-1.png 687w\"><figcaption><span style=\"white-space: pre-wrap;\">Click to view in HD<\/span><\/figcaption><\/figure><p>Another way is to use the <a href=\"https:\/\/awspolicygen.s3.amazonaws.com\/policygen.html?ref=devopscube.com\" rel=\"noreferrer noopener\">aws policy generator.<\/a><\/p><p>In the policy generator, when you select the policy resource, it will automatically show the arn suggestion as shown below. You just need to add resource information.<\/p><figure class=\"kg-card kg-image-card kg-card-hascaption\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/arn-policy-generator-min-1.png\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"703\" height=\"495\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/arn-policy-generator-min-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/arn-policy-generator-min-1.png 703w\"><figcaption><span style=\"white-space: pre-wrap;\">Click to view in HD<\/span><\/figcaption><\/figure><h2 id=\"arn-wildcards\">ARN Wildcards<\/h2><p>ARN definition supports wildcards. You will need a wildcard in many use cases.<\/p><p>Let&#8217;s say you want an IAM policy that allows access to all objects in a single bucket. For this, you can have a wildcard arn like below.<\/p><pre><code>arn:aws:s3:::my-data-bucket\/*<\/code><\/pre><p>Here is an example of using wildcard arn in an IAM policy. This policy allows all actions for <code>dcubebucket<\/code> S3 bucket.<\/p><pre><code>{\n\t\"Version\": \"2012-10-17\",\n\t\"Statement\": [{\n\t\t\"Sid\": \"Stmt1596173683332\",\n\t\t\"Action\": \"s3:*\",\n\t\t\"Effect\": \"Allow\",\n\t\t\"Resource\": [\n\t\t\t\"arn:aws:s3:::dcubebucket\",\n\t\t\t\"arn:aws:s3:::dcubebucket\/*\"\n\t\t]\n\t}]\n}<\/code><\/pre><p>Here is another example policy that allows limited access to all emr clusters.<\/p><pre><code>{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Sid\": \"Stmt1596174145144\",\n      \"Action\": [\n        \"elasticmapreduce:AddInstanceFleet\",\n        \"elasticmapreduce:AddTags\",\n        \"elasticmapreduce:DescribeCluster\",\n        \"elasticmapreduce:DescribeEditor\",\n        \"elasticmapreduce:DescribeJobFlows\",\n        \"elasticmapreduce:DescribeSecurityConfiguration\"\n      ],\n      \"Effect\": \"Allow\",\n      \"Resource\": \"arn:aws:elasticmapreduce:*:*:cluster\/*\"\n    }\n  ]\n}<\/code><\/pre><h2 id=\"arn-paths\">ARN Paths<\/h2><p>In some cases using wildecard is not recommend monstly in IAM policies which can give access to evey resiurces comes under the wildcard, this is where path comes in handy.<\/p><p>Paths are used to identify specific resources inside a resource type and it is a way to structure resources within AWS services that support hierarchical resource naming.<\/p><p>Paths are specified at the end of the arn, and each path is separated by ( \/ ) based on its path structure.<\/p><p>For example, if you want to give access to a group of users to a specific folder inside the bucket while restricting access to all other folders on a bucket, you can use arn paths to give access only to a specific folder<\/p><pre><code>arn:aws:s3:::example-bucket\/folder<\/code><\/pre><p>Here is an example of using arn path in an IAM policy. This policy allows the user to access only the folder dev inside the <code>dcubebucke<\/code>t S3 bucket.<\/p><pre><code>{\n  \"Version\": \"2012-10-17\",\n  \"Statement\": [\n    {\n      \"Effect\": \"Allow\",\n      \"Action\": \"s3:ListBucket\",\n      \"Resource\": \"arn:aws:s3:::dcubebucket\/dev\/*\",\n      \"Condition\": {\n        \"StringLike\": {\n          \"aws:userid\": \"12345678910\/development\/*\"\n        }\n      }\n    }\n  ]\n}\n<\/code><\/pre><p>This policy gives access to users who come under development on the folder dev inside the S3 bucket dcubebucket.<\/p><h2 id=\"getting-arn-from-aws-cli\">Getting ARN from AWS CLI<\/h2><p>You can get the ARN of specific resources from the CLI.<\/p><p>For all <a href=\"https:\/\/devopscube.com\/aws-iam-role-instance-profile\/\">IAM roles<\/a>, policies, and users, you can get the ARN from the CLI by describing it.<\/p><p>Here is an example of getting arn of a role.<\/p><pre><code>aws iam get-role --role-name EMR_DefaultRole<\/code><\/pre><p>Here is the output with the arn.<\/p><figure class=\"kg-card kg-image-card\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/aws-arn-cli-min-1.png\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"471\" height=\"435\"><\/figure><p>Like this, you can try describing the resource and see if it outputs the arn.<\/p><h2 id=\"getting-arn-from-aws-console\">Getting ARN from AWS Console<\/h2><p>You can get the arn of IAM resources directly from the AWS console.<\/p><p>Just browse to the specific resource and you will find the related arn at the top as shown below.<\/p><figure class=\"kg-card kg-image-card kg-card-hascaption\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/iam-arm-console-min-1.png\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"744\" height=\"562\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/iam-arm-console-min-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/iam-arm-console-min-1.png 744w\" sizes=\"auto, (min-width: 720px) 720px\"><figcaption><span style=\"white-space: pre-wrap;\">Click to view in HD<\/span><\/figcaption><\/figure><h2 id=\"getting-arn-as-output-in-cloudformation\">Getting ARN as Output in Cloudformation<\/h2><p>If you are using Cloudformation, you can get the resource arn in the output with the function <code>Fn::GetAtt<\/code><\/p><p>Here is an example syntax of getting the arn of a Lambda function.<\/p><pre><code>resources:\n  Outputs:\n    LamdaFunctionArn:\n      Export:\n        Name: MyFucntionARN\n      Value:\n        Fn::GetAtt: MyLambdaFunction.Arn<\/code><\/pre><h2 id=\"getting-arn-of-principal\">Getting ARN of Principal<\/h2><p>When you create an S3 bucket policy, SNS topic, VPC endpoint, and SQS policy, you need to specify a principal parameter.<\/p><p><code>Principal<\/code> Is the trusted source specified as an ARN in the policy to allow or deny access to the resource<\/p><p>For example, if you want an S3 bucket to be accessed only by a specific user, you will specify the user arn as <code>Principal<\/code> in the policy.<\/p><p>If you use a <a href=\"https:\/\/awspolicygen.s3.amazonaws.com\/policygen.html?ref=devopscube.com\" rel=\"noreferrer noopener\">Policy generator<\/a> to create these policies, you will see the principal option as shown below.<\/p><figure class=\"kg-card kg-image-card kg-card-hascaption\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/arn-principal-min-1.png\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"1544\" height=\"680\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/arn-principal-min-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/arn-principal-min-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/arn-principal-min-1.png 1544w\" sizes=\"auto, (min-width: 720px) 720px\"><figcaption><span style=\"white-space: pre-wrap;\">Click to view in HD<\/span><\/figcaption><\/figure><p>Primarily you specify the user, account, and role arn as the principal. There are other Principal sources as well. Please see this AWS document to learn more.<\/p><h4 id=\"getting-the-user-arn\">Getting the User arn<\/h4><p>If you browse the user page in the AWS console, you will get the user arn as shown below.<\/p><figure class=\"kg-card kg-image-card kg-card-hascaption\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/user-arn-min-1.png\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"1214\" height=\"442\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/user-arn-min-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/user-arn-min-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/user-arn-min-1.png 1214w\" sizes=\"auto, (min-width: 720px) 720px\"><figcaption><span style=\"white-space: pre-wrap;\">Click to view in HD<\/span><\/figcaption><\/figure><h4 id=\"aws-account-arn\">AWS Account arn<\/h4><p>AWS account arn has the following syntax. Replace <code>account-id<\/code> with your account id.<\/p><pre><code>arn:aws:iam::&lt;account-id&gt;:root<\/code><\/pre><h4 id=\"getting-an-aws-role-arn\">Getting an AWS Role arn<\/h4><p>You can get the arn of the IAM role from the cli as explained in the above section.<\/p><p>If you go to<strong> IAM &#8211;&gt; Role &#8211;&gt; Your role<\/strong> from the web console, you can view the arn as shown below.<\/p><div class=\"kg-card kg-callout-card kg-callout-card-grey\"><div class=\"kg-callout-text\"><b><strong style=\"white-space: pre-wrap;\">Note: <\/strong><\/b>If you are working with an ec2 instance, you might need the instance profile arn with the IAM policies.<\/div><\/div><figure class=\"kg-card kg-image-card kg-card-hascaption\"><img decoding=\"async\" src=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/role-min-1.png\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"1612\" height=\"592\" srcset=\"https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w600\/2025\/03\/role-min-1.png 600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1000\/2025\/03\/role-min-1.png 1000w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/size\/w1600\/2025\/03\/role-min-1.png 1600w, https:\/\/storage.ghost.io\/c\/5f\/2f\/5f2f4d20-2abf-4534-8d40-7aa233aedd43\/content\/images\/2025\/03\/role-min-1.png 1612w\" sizes=\"auto, (min-width: 720px) 720px\"><figcaption><span style=\"white-space: pre-wrap;\">Click to view in HD<\/span><\/figcaption><\/figure><h2 id=\"wrapping-up\">Wrapping Up<\/h2><p>I have added some of the resources and tricks I use for aws arn.<\/p><p>I would like to hear from you.<\/p><p>Please let me some scenarios you have come across in the comments section.<\/p><p>You might also like <a href=\"https:\/\/devopscube.com\/aws-load-balancers\/\">AWS Load Balancer Concepts<\/a>.<\/p>\n<hr><p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/aws-arn-guide\/\" target=\"_blank\" rel=\"noopener noreferrer\">AWS ARN Explained: Amazon Resource Name Beginners Guide \u2014 DevOpsCube<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/aws-arn-guide\/<\/p>\n","protected":false},"author":1,"featured_media":549,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-548","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=548"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/548\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/549"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}