{"id":2050,"date":"2024-01-24T10:49:10","date_gmt":"2024-01-24T01:49:10","guid":{"rendered":"https:\/\/www.kwonline.org\/memo2\/?p=2050"},"modified":"2024-01-25T23:13:54","modified_gmt":"2024-01-25T14:13:54","slug":"sts-assume-role-to-connect-s3-from-ec2","status":"publish","type":"post","link":"https:\/\/www.kwonline.org\/memo2\/2024\/01\/24\/sts-assume-role-to-connect-s3-from-ec2\/","title":{"rendered":"AWS: EC2 \u304b\u3089 S3 \u306b STS AssumeRole \u3067\u63a5\u7d9a\u3059\u308b"},"content":{"rendered":"<p>&nbsp;<br \/>\nS3 \u63a5\u7d9a\u3067 STS AssumeRole \u3092\u4f7f\u3046\u5fc5\u8981\u304c\u3042\u3063\u305f\u306e\u3067\u30e1\u30e2<\/p>\n<p>\u307e\u305a\u306f EC2 \u306b\u30a2\u30bf\u30c3\u30c1\u3059\u308b IAM Role \u306e Trust Relationships (\u4fe1\u983c\u95a2\u4fc2) \u30bf\u30d6\u306e\u4e2d\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u4fee\u6b63\u3059\u308b\u3002<\/p>\n<p>\u4e0b\u8a18\u306ePrincipal.AWS \u306e\u5024\u306e\u3068\u3053\u308d\u306b\u306f ARN \u3092\u30bb\u30c3\u30c8\u3059\u308b\u3002<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n{\r\n    &quot;Version&quot;: &quot;2012-10-17&quot;,\r\n    &quot;Statement&quot;: &#x5B;\r\n        {\r\n            &quot;Effect&quot;: &quot;Allow&quot;,\r\n            &quot;Principal&quot;: {\r\n                &quot;Service&quot;: &quot;ec2.amazonaws.com&quot;\r\n            },\r\n            &quot;Action&quot;: &quot;sts:AssumeRole&quot;\r\n        },\r\n        {\r\n            &quot;Effect&quot;: &quot;Allow&quot;,\r\n            &quot;Principal&quot;: {\r\n                &quot;AWS&quot;: &quot;arn:aws:iam::&lt;ACCOUNT-HERE&gt;:role\/&lt;ROLE-HERE&gt;&quot;\r\n            },\r\n            &quot;Action&quot;: &quot;sts:AssumeRole&quot;\r\n        }\r\n    ]\r\n}\r\n<\/pre>\n<p>&nbsp;<br \/>\n\u6b21\u306f EC2.<\/p>\n<p>EC2 \u306b ssh \u30ed\u30b0\u30a4\u30f3\u3057\u3066 awscli \u3067 AssumeRole \u3057\u3066\u304b\u3089\u74b0\u5883\u5909\u6570\u306b\u5024\u3092\u30bb\u30c3\u30c8\u3059\u308b\u3002<br \/>\n&#8211;role-arn \u306b\u306f\u4e0a\u8a18\u3068\u540c\u3058\u304f EC2 \u306b\u30a2\u30bf\u30c3\u30c1\u3059\u308b Role \u306e ARN \u3092\u6e21\u3059\u3002<\/p>\n<p>jq \u30b3\u30de\u30f3\u30c9\u4f7f\u3063\u3066 JSON \u30d1\u30fc\u30b9\u3059\u308c\u3070\u697d\u3002<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\nOUTPUT=$(aws sts assume-role --role-arn &quot;arn:aws:iam::&lt;ACCOUNT-HERE&gt;:role\/&lt;ROLE-HERE&gt;&quot; --role-session-name AWSCLI-Session)\r\nexport AWS_ACCESS_KEY_ID=$(echo $OUTPUT | jq -r '.Credentials.AccessKeyId')\r\nexport AWS_SECRET_ACCESS_KEY=$(echo $OUTPUT | jq -r '.Credentials.SecretAccessKey')\r\nexport AWS_SESSION_TOKEN=$(echo $OUTPUT | jq -r '.Credentials.SessionToken')\r\n<\/pre>\n<p>S3 \u306b\u30a2\u30af\u30bb\u30b9\u51fa\u6765\u308b\u304b\u78ba\u8a8d<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\naws s3api list-objects --bucket your-bucket-name --region ap-northeast-1\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; S3 \u63a5\u7d9a\u3067 STS AssumeRole \u3092\u4f7f\u3046\u5fc5\u8981\u304c\u3042\u3063\u305f\u306e\u3067\u30e1\u30e2 \u307e\u305a\u306f EC2 \u306b\u30a2\u30bf\u30c3\u30c1\u3059\u308b IAM Role \u306e Trust Relationships (\u4fe1\u983c\u95a2\u4fc2) \u30bf\u30d6\u306e\u4e2d\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u4fee\u6b63 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25,8],"tags":[],"class_list":["post-2050","post","type-post","status-publish","format-standard","hentry","category-aws","category-linux"],"_links":{"self":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/2050","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/comments?post=2050"}],"version-history":[{"count":7,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/2050\/revisions"}],"predecessor-version":[{"id":2059,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/2050\/revisions\/2059"}],"wp:attachment":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/media?parent=2050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/categories?post=2050"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/tags?post=2050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}