{"id":1820,"date":"2025-01-15T14:36:22","date_gmt":"2025-01-15T06:36:22","guid":{"rendered":"https:\/\/www.fanyamin.com\/wordpress\/?p=1820"},"modified":"2025-01-15T14:36:39","modified_gmt":"2025-01-15T06:36:39","slug":"%e4%bb%80%e4%b9%88%e6%98%af-instance-profile%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.fanyamin.com\/wordpress\/?p=1820","title":{"rendered":"\u4ec0\u4e48\u662f Instance Profile\uff1f"},"content":{"rendered":"<h3><strong>\u4ec0\u4e48\u662f Instance Profile\uff1f<\/strong><\/h3>\n<p>\u5728 AWS \u4e2d\uff0c<strong>Instance Profile<\/strong> \u662f\u4e00\u79cd\u7279\u6b8a\u7684\u5bb9\u5668\uff0c\u7528\u4e8e\u5c06 IAM \u89d2\u8272\u9644\u52a0\u5230 EC2 \u5b9e\u4f8b\u4e0a\uff0c\u4f7f\u5b9e\u4f8b\u5185\u7684\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u4ee5\u89d2\u8272\u7684\u6743\u9650\u6765\u8bbf\u95ee AWS \u670d\u52a1\u3002Instance Profile \u662f IAM \u89d2\u8272\u4e0e EC2 \u5b9e\u4f8b\u4e4b\u95f4\u7684\u6865\u6881\uff0c\u5b83\u5141\u8bb8\u89d2\u8272\u7684\u4e34\u65f6\u51ed\u8bc1\u901a\u8fc7 EC2 \u7684\u5b9e\u4f8b\u5143\u6570\u636e\u670d\u52a1\u63d0\u4f9b\u7ed9\u5b9e\u4f8b\u5185\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<hr \/>\n<h3><strong>Instance Profile \u7684\u4f5c\u7528<\/strong><\/h3>\n<ol>\n<li>\n<p><strong>\u4e3a EC2 \u5b9e\u4f8b\u63d0\u4f9b IAM \u89d2\u8272\u7684\u6743\u9650<\/strong>\uff1a<\/p>\n<ul>\n<li>\u901a\u8fc7\u5c06 Instance Profile \u5173\u8054\u5230 EC2 \u5b9e\u4f8b\uff0c\u5b9e\u4f8b\u4e2d\u7684\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u5b89\u5168\u5730\u4f7f\u7528 IAM \u89d2\u8272\u7684\u6743\u9650\uff0c\u800c\u65e0\u9700\u5d4c\u5165 AWS \u5bc6\u94a5\u6216\u51ed\u8bc1\u5230\u4ee3\u7801\u4e2d\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u81ea\u52a8\u83b7\u53d6\u4e34\u65f6\u51ed\u8bc1<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 AWS SDK\u3001CLI \u6216\u8005\u5b9e\u4f8b\u5143\u6570\u636e\u670d\u52a1\uff0c\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u81ea\u52a8\u83b7\u53d6\u4e0e\u89d2\u8272\u76f8\u5173\u8054\u7684\u4e34\u65f6\u51ed\u8bc1\uff0c\u907f\u514d\u624b\u52a8\u7ba1\u7406\u957f\u671f\u51ed\u8bc1\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u63d0\u5347\u5b89\u5168\u6027<\/strong>\uff1a<\/p>\n<ul>\n<li>\u907f\u514d\u5c06\u957f\u671f\u8bbf\u95ee\u5bc6\u94a5\u5b58\u50a8\u5728 EC2 \u5b9e\u4f8b\u4e2d\uff0c\u964d\u4f4e\u5bc6\u94a5\u6cc4\u6f0f\u98ce\u9669\u3002<\/li>\n<li>\u914d\u5408 IAM \u7b56\u7565\uff0c\u786e\u4fdd\u5b9e\u4f8b\u53ea\u80fd\u8bbf\u95ee\u6240\u9700\u7684\u6700\u5c0f\u8d44\u6e90\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u652f\u6301\u52a8\u6001\u6743\u9650\u8c03\u6574<\/strong>\uff1a<\/p>\n<ul>\n<li>\u901a\u8fc7\u4fee\u6539 IAM \u89d2\u8272\u6216\u7b56\u7565\uff0c\u53ef\u4ee5\u5373\u65f6\u8c03\u6574\u6743\u9650\uff0c\u65e0\u9700\u91cd\u542f\u5b9e\u4f8b\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr \/>\n<h3><strong>Instance Profile \u7684\u5de5\u4f5c\u673a\u5236<\/strong><\/h3>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u89d2\u8272\u548c\u7b56\u7565<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5728 IAM \u4e2d\u521b\u5efa\u4e00\u4e2a\u89d2\u8272\uff0c\u5e76\u9644\u52a0\u5fc5\u8981\u7684\u6743\u9650\u7b56\u7565\uff0c\u4f8b\u5982 <code>AmazonS3ReadOnlyAccess<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u521b\u5efa Instance Profile<\/strong>\uff1a<\/p>\n<ul>\n<li>\u81ea\u52a8\u521b\u5efa\u7684\u8fc7\u7a0b\uff1a\n<ul>\n<li>\u5728 AWS \u63a7\u5236\u53f0\u521b\u5efa EC2 \u5b9e\u4f8b\u65f6\uff0c\u9009\u62e9\u4e00\u4e2a IAM \u89d2\u8272\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a\u5bf9\u5e94\u7684 Instance Profile\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\u624b\u52a8\u521b\u5efa\u7684\u8fc7\u7a0b\uff1a\n<ul>\n<li>\u4f7f\u7528 AWS CLI \u6216 API \u521b\u5efa\u4e00\u4e2a Instance Profile\uff0c\u5e76\u5c06 IAM \u89d2\u8272\u5173\u8054\u5230\u5b83\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u9644\u52a0\u5230 EC2 \u5b9e\u4f8b<\/strong>\uff1a<\/p>\n<ul>\n<li>\u542f\u52a8 EC2 \u5b9e\u4f8b\u65f6\uff0c\u9009\u62e9\u4e00\u4e2a\u5df2\u5173\u8054 Instance Profile \u7684 IAM \u89d2\u8272\u3002<\/li>\n<li>\u5982\u679c\u5b9e\u4f8b\u5df2\u8fd0\u884c\uff0c\u53ef\u4ee5\u4f7f\u7528 AWS CLI \u6216\u63a7\u5236\u53f0\u9644\u52a0 Instance Profile\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528\u4e34\u65f6\u51ed\u8bc1<\/strong>\uff1a<\/p>\n<ul>\n<li>EC2 \u5b9e\u4f8b\u901a\u8fc7 <strong>\u5b9e\u4f8b\u5143\u6570\u636e\u670d\u52a1 (IMDS)<\/strong> \u81ea\u52a8\u63d0\u4f9b\u4e34\u65f6\u51ed\u8bc1\u3002<\/li>\n<li>\u5e94\u7528\u7a0b\u5e8f\u901a\u8fc7 AWS SDK \u6216 CLI \u8c03\u7528 AWS \u670d\u52a1\u65f6\uff0cSDK \u4f1a\u4ece\u5143\u6570\u636e\u670d\u52a1\u81ea\u52a8\u83b7\u53d6\u51ed\u8bc1\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr \/>\n<h3><strong>\u5178\u578b\u4f7f\u7528\u573a\u666f<\/strong><\/h3>\n<ol>\n<li>\n<p><strong>\u8bbf\u95ee AWS \u670d\u52a1<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f8b\u5982\uff0c\u8fd0\u884c\u5728 EC2 \u5b9e\u4f8b\u4e0a\u7684\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u8bbf\u95ee S3 \u5b58\u50a8\u6876\u3001DynamoDB \u8868\u7b49 AWS \u670d\u52a1\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u81ea\u52a8\u5316\u4efb\u52a1<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 EC2 \u5b9e\u4f8b\u6267\u884c\u6279\u5904\u7406\u4efb\u52a1\uff0c\u8bbf\u95ee AWS \u8d44\u6e90\uff08\u5982 Secrets Manager \u6216 Parameter Store\uff09\u4ee5\u83b7\u53d6\u5bc6\u94a5\u6216\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u76d1\u63a7\u548c\u65e5\u5fd7\u6536\u96c6<\/strong>\uff1a<\/p>\n<ul>\n<li>\u8fd0\u884c\u5728 EC2 \u5b9e\u4f8b\u4e0a\u7684\u4ee3\u7406\uff08\u5982 CloudWatch Agent\u3001Elastic Agent\uff09\u9700\u8981\u4e0a\u4f20\u65e5\u5fd7\u6216\u6307\u6807\u5230 AWS \u670d\u52a1\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u5bb9\u5668\u5316\u5de5\u4f5c\u8d1f\u8f7d<\/strong>\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528 EC2 \u5b9e\u4f8b\u8fd0\u884c\u5bb9\u5668\uff0c\u5bb9\u5668\u4e2d\u7684\u4efb\u52a1\u901a\u8fc7 Instance Profile \u83b7\u53d6\u4e34\u65f6\u51ed\u8bc1\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr \/>\n<h3><strong>Instance Profile \u548c IAM \u89d2\u8272\u7684\u5173\u7cfb<\/strong><\/h3>\n<table>\n<thead>\n<tr>\n<th><strong>\u7279\u6027<\/strong><\/th>\n<th><strong>Instance Profile<\/strong><\/th>\n<th><strong>IAM \u89d2\u8272<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u5b9a\u4e49<\/strong><\/td>\n<td>IAM \u89d2\u8272\u7684\u5bb9\u5668\uff0c\u4e13\u95e8\u7528\u4e8e EC2 \u5b9e\u4f8b\u3002<\/td>\n<td>\u5b9a\u4e49\u6743\u9650\u7b56\u7565\u5e76\u6388\u4e88\u6743\u9650\u7684 AWS \u5b9e\u4f53\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u76ee\u6807<\/strong><\/td>\n<td>\u9644\u52a0\u5230 EC2 \u5b9e\u4f8b\u4ee5\u63d0\u4f9b IAM \u89d2\u8272\u6743\u9650\u3002<\/td>\n<td>\u6388\u6743 AWS \u670d\u52a1\u3001\u7528\u6237\u6216\u5e94\u7528\u7a0b\u5e8f\u8bbf\u95ee\u8d44\u6e90\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u9644\u52a0\u5173\u7cfb<\/strong><\/td>\n<td>\u4e00\u4e2a EC2 \u5b9e\u4f8b\u53ea\u80fd\u6709\u4e00\u4e2a Instance Profile\u3002<\/td>\n<td>\u4e00\u4e2a\u89d2\u8272\u53ef\u4ee5\u7528\u4e8e\u591a\u4e2a Instance Profile\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u4f9d\u8d56\u5173\u7cfb<\/strong><\/td>\n<td>\u5fc5\u987b\u5305\u542b IAM \u89d2\u8272\u3002<\/td>\n<td>\u4e0d\u4f9d\u8d56 Instance Profile\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3><strong>\u5982\u4f55\u521b\u5efa\u548c\u4f7f\u7528 Instance Profile<\/strong><\/h3>\n<h4><strong>1. \u521b\u5efa\u89d2\u8272\u548c\u7b56\u7565<\/strong><\/h4>\n<pre><code class=\"language-bash\">aws iam create-role --role-name MyEC2Role --assume-role-policy-document file:\/\/trust-policy.json\naws iam attach-role-policy --role-name MyEC2Role --policy-arn arn:aws:iam::aws:policy\/AmazonS3ReadOnlyAccess<\/code><\/pre>\n<h4><strong>2. \u521b\u5efa Instance Profile \u5e76\u9644\u52a0\u89d2\u8272<\/strong><\/h4>\n<pre><code class=\"language-bash\">aws iam create-instance-profile --instance-profile-name MyEC2InstanceProfile\naws iam add-role-to-instance-profile --instance-profile-name MyEC2InstanceProfile --role-name MyEC2Role<\/code><\/pre>\n<h4><strong>3. \u542f\u52a8 EC2 \u5b9e\u4f8b\u5e76\u5173\u8054 Instance Profile<\/strong><\/h4>\n<p>\u5728 AWS \u63a7\u5236\u53f0\u542f\u52a8\u5b9e\u4f8b\u65f6\uff0c\u9009\u62e9\u521a\u521b\u5efa\u7684 IAM \u89d2\u8272\u3002<\/p>\n<h4><strong>4. \u9a8c\u8bc1\u5b9e\u4f8b\u662f\u5426\u53ef\u4ee5\u8bbf\u95ee AWS \u670d\u52a1<\/strong><\/h4>\n<p>\u767b\u5f55 EC2 \u5b9e\u4f8b\uff0c\u4f7f\u7528 AWS CLI \u6216 SDK \u6d4b\u8bd5\u8bbf\u95ee AWS \u670d\u52a1\uff1a<\/p>\n<pre><code class=\"language-bash\">aws s3 ls<\/code><\/pre>\n<hr \/>\n<h3><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/h3>\n<ol>\n<li><strong>\u4e00\u4e2a EC2 \u5b9e\u4f8b\u53ea\u80fd\u5173\u8054\u4e00\u4e2a Instance Profile<\/strong>\u3002<\/li>\n<li><strong>\u6743\u9650\u66f4\u65b0\u5373\u65f6\u751f\u6548<\/strong>\uff1a\n<ul>\n<li>\u4fee\u6539 IAM \u89d2\u8272\u7684\u7b56\u7565\u4f1a\u7acb\u5373\u751f\u6548\uff0c\u65e0\u9700\u91cd\u542f\u5b9e\u4f8b\u3002<\/li>\n<\/ul>\n<\/li>\n<li><strong>\u5b9e\u4f8b\u5143\u6570\u636e\u670d\u52a1\u7248\u672c<\/strong>\uff1a\n<ul>\n<li>\u4f7f\u7528 <strong>IMDSv2<\/strong>\uff08\u5b9e\u4f8b\u5143\u6570\u636e\u670d\u52a1\u7248\u672c 2\uff09\u589e\u5f3a\u5b89\u5168\u6027\uff0c\u907f\u514d\u51ed\u8bc1\u6cc4\u6f0f\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<hr \/>\n<h3><strong>\u603b\u7ed3<\/strong><\/h3>\n<p>Instance Profile \u662f EC2 \u5b9e\u4f8b\u8bbf\u95ee AWS \u670d\u52a1\u7684\u5173\u952e\u6865\u6881\u3002\u901a\u8fc7\u52a8\u6001\u83b7\u53d6\u4e34\u65f6\u51ed\u8bc1\uff0c\u5b83\u4e3a EC2 \u63d0\u4f9b\u4e86\u5b89\u5168\u9ad8\u6548\u7684\u8eab\u4efd\u9a8c\u8bc1\u673a\u5236\uff0c\u540c\u65f6\u5927\u5e45\u51cf\u5c11\u4e86\u957f\u671f\u51ed\u8bc1\u7684\u7ba1\u7406\u590d\u6742\u6027\uff0c\u662f\u9075\u5faa AWS \u5b89\u5168\u6700\u4f73\u5b9e\u8df5\u7684\u91cd\u8981\u5de5\u5177\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ec0\u4e48\u662f Instance Profile\uff1f \u5728 AWS \u4e2d\uff0cInstance Profile \u662f\u4e00\u79cd\u7279\u6b8a\u7684\u5bb9\u5668\uff0c\u7528\u4e8e\u5c06 IAM \u89d2\u8272\u9644\u52a0\u5230 EC2 \u5b9e\u4f8b\u4e0a\uff0c\u4f7f\u5b9e\u4f8b\u5185\u7684\u5e94\u7528\u7a0b\u5e8f\u80fd\u591f\u4ee5\u89d2\u8272\u7684\u6743\u9650\u6765\u8bbf\u95ee AWS \u670d\u52a1\u3002Instance Profile \u662f IAM \u89d2\u8272\u4e0e EC2 \u5b9e\u4f8b\u4e4b\u95f4\u7684\u6865\u6881\uff0c\u5b83\u5141\u8bb8\u89d2\u8272\u7684\u4e34\u65f6\u51ed\u8bc1\u901a\u8fc7 EC2 \u7684\u5b9e\u4f8b\u5143\u6570\u636e\u670d\u52a1\u63d0\u4f9b\u7ed9\u5b9e\u4f8b\u5185\u7684\u5e94\u7528\u7a0b\u5e8f\u3002 Instance Profile \u7684\u4f5c\u7528 \u4e3a EC2 \u5b9e\u4f8b\u63d0\u4f9b IAM \u89d2\u8272\u7684\u6743\u9650\uff1a \u901a\u8fc7\u5c06 Instance Profile \u5173\u8054\u5230 EC2 \u5b9e\u4f8b\uff0c\u5b9e\u4f8b\u4e2d\u7684\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u5b89\u5168\u5730\u4f7f\u7528 IAM \u89d2\u8272\u7684\u6743\u9650\uff0c\u800c\u65e0\u9700\u5d4c\u5165 AWS \u5bc6\u94a5\u6216\u51ed\u8bc1\u5230\u4ee3\u7801\u4e2d\u3002 \u81ea\u52a8\u83b7\u53d6\u4e34\u65f6\u51ed\u8bc1\uff1a \u4f7f\u7528 AWS SDK\u3001CLI \u6216\u8005\u5b9e\u4f8b\u5143\u6570\u636e\u670d\u52a1\uff0c\u5e94\u7528\u7a0b\u5e8f\u53ef\u4ee5\u81ea\u52a8\u83b7\u53d6\u4e0e\u89d2\u8272\u76f8\u5173\u8054\u7684\u4e34\u65f6\u51ed\u8bc1\uff0c\u907f\u514d\u624b\u52a8\u7ba1\u7406\u957f\u671f\u51ed\u8bc1\u3002 \u63d0\u5347\u5b89\u5168\u6027\uff1a \u907f\u514d\u5c06\u957f\u671f\u8bbf\u95ee\u5bc6\u94a5\u5b58\u50a8\u5728 EC2 \u5b9e\u4f8b\u4e2d\uff0c\u964d\u4f4e\u5bc6\u94a5\u6cc4\u6f0f\u98ce\u9669\u3002 \u914d\u5408 IAM \u7b56\u7565\uff0c\u786e\u4fdd\u5b9e\u4f8b\u53ea\u80fd\u8bbf\u95ee\u6240\u9700\u7684\u6700\u5c0f\u8d44\u6e90\u3002 \u652f\u6301\u52a8\u6001\u6743\u9650\u8c03\u6574\uff1a \u901a\u8fc7\u4fee\u6539 IAM [&hellip;] <a class=\"read-more\" href=\"https:\/\/www.fanyamin.com\/wordpress\/?p=1820\" title=\"Permanent Link to: \u4ec0\u4e48\u662f Instance Profile\uff1f\">&rarr;Read&nbsp;more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-1820","post","type-post","status-publish","format-standard","hentry","category-cloud"],"_links":{"self":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1820"}],"collection":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1820"}],"version-history":[{"count":1,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1820\/revisions"}],"predecessor-version":[{"id":1821,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1820\/revisions\/1821"}],"wp:attachment":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1820"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1820"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1820"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}