ããã«ã¡ã¯ãAWS CLIã好ããªç¦å³¶ã§ãã
ã¯ããã«
ä»åã¯ãAWS SSOçµç±ã§AWSã¸GUIã¾ãã¯CLIã使ãã¢ã¯ã»ã¹ããæ¹æ³ãããã°ã«è¨è¼ãããã¾ãã
GUIã«ããã¢ã¯ã»ã¹æ¹æ³
â ã¦ã¼ã¶ã¼ãã¼ã¿ã«URLã¸ã®ã¢ã¯ã»ã¹
AWS SSOã®è¨å®ãè¡ãã¨ãã¦ã¼ã¶ã¼ãã¼ã¿ã«URLãæãåºãããããããã®URLã¸ã¢ã¯ã»ã¹ãã¾ãã
åºæ¬çã«ä»¥ä¸ã®ãããªURLãæãåºããã¾ãã
https://d-XXXXXXXXX.awsapps.com/start
â¡ã¦ã¼ã¶ã¼åã®å ¥å
以ä¸ã®ç»é¢ã¯ãã¢ã¤ãã³ãã£ãã£ã½ã¼ã¹ãAWS SSOã®å ´åã®ãããã¢ã¤ãã³ãã£ãã£ã½ã¼ã¹ãå¤é¨IDãããã¤ãã¼ã®å ´åãç»é¢ãç°ãªãã¾ãã
ã¾ããæ¢ã«èªè¨¼ããã¦ããå ´åã¯ãâ¡,â¢,â£ãé£ã°ããâ¤ãã確èªãã ããã
â¢ãã¹ã¯ã¼ãã®å ¥å
â£MFAã®å ¥å
â¤AWSã¢ã«ã¦ã³ãã¸ã®ã¢ã¯ã»ã¹
ãã°ã¤ã³ãããã¢ã«ã¦ã³ãããã³æ¨©éã®å³è¨ã«è¨è¼ã®ãManagement consoleããæ¼ä¸ãã¾ãã
â¥ãã°ã¤ã³ç¢ºèª
ãã°ã¤ã³å¾ãå³ä¸ãããã°ã¤ã³ããã¢ã«ã¦ã³ãIDããã³ã¢ã¯ã»ã¹ã«å©ç¨ããIAMãã¼ã«ã確èªã§ãã¾ãã
CLIã«ããã¢ã¯ã»ã¹æ¹æ³
â AWS CLIã®å°å ¥
以ä¸ãåèã«ãAWSCLIãå°å ¥ãã¾ãã
â¡SSOã®è¨å®
~/.aws/configã«ä»¥ä¸ã®è¨å®ãè¡ãã¾ãã
[profile ãä»»æã®ååã] sso_start_url = ãã¦ã¼ã¶ã¼ãã¼ã¿ã«URLã sso_region = ap-northeast-1 sso_account_id = ãæä½ãããã¢ã«ã¦ã³ãIDã sso_role_name = ãIAMãã¼ã«ã region = ap-northeast-1 output = json
â»è¤æ°åå¨ããå ´åãè¤æ°è¨å®å¯è½ã§ãããprofileã®ååã¯éè¤ããªããã注æãå¿ è¦ã§ãã
- è¨å®ä¾
[profile dev-account-ro] sso_start_url = https://d-XXXXXXXXX.awsapps.com/start sso_region = ap-northeast-1 sso_account_id = 123456789011 sso_role_name = ReadOnly region = ap-northeast-1 output = json [profile dev-account-admin] sso_start_url = https://d-XXXXXXXXX.awsapps.com/start sso_region = ap-northeast-1 sso_account_id = 123456789011 sso_role_name = Administrator region = ap-northeast-1 output = json
â¢SSOã¸ã®ãã°ã¤ã³
以ä¸ã®ã³ãã³ããå®è¡ãã¾ãã
# aws sso login --profile [ãããã¡ã¤ã«å]
- å®è¡ä¾
# aws sso login --profile dev-account-ro Attempting to automatically open the SSO authorization page in your default browser. If the browser does not open or you wish to use a different device to authorize this request, open the following URL: https://device.sso.us-west-2.amazonaws.com/ Then enter the code: XXXX-XXXX
ãã©ã¦ã¶ãéãã以ä¸ã®ç»é¢ãéããããAllowãæ¼ä¸ãã¾ãã 以ä¸ã®ç»é¢ã§ã¯ãªãèªè¨¼ç»é¢ãåºã¦ããå ´åãèªè¨¼æ å ±ãå ¥åãã¾ãã(åè: GUIã«ããã¢ã¯ã»ã¹æ¹æ³ã®â¡~â£)
â£ã³ãã³ãã®å®è¡
æ£å¸¸ã«ãã°ã¤ã³åºæ¥ãããã³ãã³ããå®è¡ã§ãããã¨åãã¾ãã
# aws sts get-caller-identity --profile dev-account-ro { "UserId": "AROAZXTTGY3YRWGO2F72K:fukushima", "Account": "123456789012", "Arn": "arn:aws:sts::123456789012:assumed-role/AWSReservedSSO_ReadOnlyAccess_8b8b53132b3ea1a0/fukushima" } #
ã¾ããããã°ã©ãã³ã°è¨èª(以ä¸ã¯Pythonã®ä¾)ãå®è¡ããæ¹æ³ã¯ããã¤ãããã¾ãããä»åã¯AWS_PROFILEã®ç°å¢å¤æ°ã«ãããã¡ã¤ã«åãè¨å®ããæ¹æ³ãè¨è¼ãããã¾ãã
PS1(Linux)ã$profile(Windows)ã®è¨å®ã¯å¿ é ã§ã¯ããã¾ããããå¤æ´ãã¦ãããã¨ã§ããã³ããã«ç¾å¨è¨å®ããã¦ããAWS_PROFILEã表示ãããããã便å©ã§ãã
- ã³ã¼ãã®ãµã³ãã«(test.py)
import boto3 client = boto3.client('sts') response = client.get_caller_identity() print ('Account: ' + response['Account']) print ('Arn: ' + response['Arn'])
- Linuxã®å ´å
# PS1="\${AWS_PROFILE}# " # # export AWS_PROFILE=dev-account-ro dev-account-ro# dev-account-ro# python3 test.py Account: 1233456789012 Arn: arn:aws:sts::1233456789012:assumed-role/AWSReservedSSO_ReadOnlyAccess_8b8b53132b3ea1a0/fukushima dev-account-ro#
ä½æ¥ãæ¤è¨¼ãçµãã£ãå ´åã¯ãAWSã¸ã®èª¤ã£ãæä½ãåé¿ããããã以ä¸ã®ã³ãã³ãã§AWS_PROFILEã®å¤æ°ãåæåãããã¨ããå§ããããã¾ãã
unset AWS_PROFILE
- Windows(Powershell)ã®å ´å
$profileã«è¨å®ããã¦ãããã¡ã¤ã«ãä½æãã¾ãã
notepad $profile
ä½æãããã¡ã¤ã«ã«ä»¥ä¸ãè¨å®ãã¾ãã
function prompt () { (echo "$Env:AWS_PROFILE> ") }
> $Env:AWS_PROFILE=dev-account-ro dev-account-ro> python3 test.py Account: 1233456789012 Arn: arn:aws:sts::1233456789012:assumed-role/AWSReservedSSO_ReadOnlyAccess_8b8b53132b3ea1a0/fukushima dev-account-ro>
ä½æ¥ãæ¤è¨¼ãçµãã£ãå ´åã¯ãAWSã¸ã®èª¤ã£ãæä½ãåé¿ããããã以ä¸ã®ã³ãã³ãã§AWS_PROFILEã®å¤æ°ãåæåãããã¨ããå§ããããã¾ãã
$Env:AWS_PROFILE=$null
è£è¶³
ã¦ã¼ã¶ã¼ãã¼ã¿ã«ã®ç»é¢ããã¢ã¯ã»ã¹ãã¼ãåå¾ãCLIã«ããã¢ã¯ã»ã¹ãè¡ãæ¹æ³ãããã¾ããããã®ã¢ã¯ã»ã¹ãã¼ãæ¼æ´©ããå ´åã AWSã¸ã¢ã¯ã»ã¹ãããã¨ãå¯è½ã«ãªããããCLIã«ããã¢ã¯ã»ã¹ã¯ä¸è¨ã«è¨è¼ããæ¹æ³ã§ã¢ã¯ã»ã¹ããã®ãè¯ããã¨åãã¾ãã
â»ã¢ã¯ã»ã¹ãã¼ã¯æ°¸ç¶çã«ä½¿ããããã§ã¯ãªããä¸æçã«ä½¿ãããã®ã®ãããæ°¸ç¶çã«å©ç¨ã§ããã¢ã¯ã»ã¹ãã¼ã«æ¯ã¹ãã°ã»ãã¥ãªãã£ãªã¹ã¯ã¯ä½ãã§ãã
çµããã«
ä»åã¯ãAWS SSOã§GUI/CLIã«ããAWSã¸ã®ã¢ã¯ã»ã¹æ¹æ³ãããã°ã«è¨è¼ãããã¾ããã
ã©ãªããã®ãå½¹ã«ç«ã¦ãã°å¹¸ãã§ãã