ã¨ã³ã¿ã¼ãã©ã¤ãºã¯ã©ã¦ãé¨ã®å±±ä¸(ç¥)ã§ãã
AWS Organizationsç°å¢ä¸ã§ãè¤æ°ã®ã¢ã«ã¦ã³ããç¹å®ã®OUã«ä¸æ¬ã§ç§»åããããã£ãã®ã§ãç°¡åãªã¹ã¯ãªãããçµãã§ç§»åããã¦ã¿ã¾ããã
ä»åã®ç°å¢
ä»åã¯ã以ä¸ã®ãããªæ¡ä»¶ä¸ã§ç§»åãè¡ãã¾ãã
- Organizationsã®ç®¡çã¢ã«ã¦ã³ãã§AWS CLIãå©ç¨å¯è½ããã ããMFAã§äºè¦ç´ èªè¨¼ããã¦ããã
- åã¢ã«ã¦ã³ãã移ååã«æå±ãã¦ããOUã¯ãã©ãã©ã§ãè¯ãã
- 移åããããã¢ã«ã¦ã³ãã¯ãªã¹ãåããã¦ããã
- åã¢ã«ã¦ã³ãã®ç§»åå ã®OUã¯åä¸ã
å ·ä½çã«ã¯ãä¸å³ã®Sandbox OUã»Business OUã»IAM OU é ä¸ã®4ã¢ã«ã¦ã³ãããSuspended OUã«ç§»åãã¾ããï¼æ¤è¨¼ç°å¢ã®ããOUåã¯é©å½ã§ãããã容赦ãã ãããï¼
äºåæºå
ã¾ãã¯äºåæºåã¨ãã¦ã以ä¸ãå®æ½ãã¾ãã
- 移åããããã¢ã«ã¦ã³ãã®ä¸è¦§ãç¨æããã
- Organizationsã®ç®¡çã¢ã«ã¦ã³ãã§ä¸æèªè¨¼æ å ±ãåå¾ããã
- ã.aws/configãã«ä¸æèªè¨¼æ å ±ã®profileã追å ããã
- 移åå OUã®OU IDã確èªããã
移åããããã¢ã«ã¦ã³ãã®ä¸è¦§ãç¨æãã
以ä¸ã®ããã«ã1è¡ã«ã¤ã1ã¢ã«ã¦ã³ããè¨è¼ãããããã¹ããã¡ã¤ã«ãç¨æãã¾ãã æ¬ããã°ã§ã¯ãã¡ã¤ã«åããmove_account_list.txtãã¨ãã¾ãã
111111111111 222222222222 333333333333 444444444444 ã» ã» ã»
Organizationsã®ç®¡çã¢ã«ã¦ã³ãã§ä¸æèªè¨¼æ å ±ãåå¾ãã
以ä¸ã³ãã³ããå®è¡ããä¸æèªè¨¼æ å ±ãåå¾ãã¾ãã Organizations管çã¢ã«ã¦ã³ãã§ãAWS CLIå®è¡æã«äºè¦ç´ èªè¨¼ãå¿ è¦ã§ãªãç°å¢ã§ããã°ãæ¬æé ã¯ä¸è¦ã§ãã ã.aws/configããã¡ã¤ã«ã§è¤æ°ã® profile ã使ãåãã¦ããå ´åãOrganizations管çã¢ã«ã¦ã³ãç¨ã® profile ãæå®ãã¦ãã ããã
aws sts get-session-token --serial-number <MFAããã¤ã¹ã®ARN> --token-code <MFAãã¼ã¯ã³ã³ã¼ã>
ã³ãã³ããæåããã¨ã以ä¸ã®ãµã³ãã«ã®ãããªãä¸æèªè¨¼æ å ±ãåºåããã¾ãã æå¹æéãããããã注æãã ãããï¼Expirationã«è¨è¼ã®æå»ã¾ã§å©ç¨å¯è½ï¼
{ "Credentials": { "AccessKeyId": "ASIA574ÃÃÃÃÃÃÃÃS5UOKBD", "SecretAccessKey": "Enqe7K7Oj2VKVMÃÃÃÃÃÃÃÃÃÃÃthvYSBf86AO/H", "SessionToken": "FwoGZXIvYXdzEKX//////////wEaDG4IBEijFDaVHbCUMiKGAYqcEoXb7SEIV7yf3LTuÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃp8sLWDg7lj1Ue8jQkWAmZ8/IEtcQDSL88kSY4lExWYBAmMmdbSzkvAeo5fX7np7gPG5O5TxaxFhBCnnI/vbmo7MHZWOo+EqulN0iRm60Y3gbVKJShyJoGMijoyK/mZ/jc2wP4Uoay72yNeJUJcOr5TdZ2uhyf7yTOZomLT9GsE3Xb" "Expiration": "2024-05-28T21:31:35+00:00" } }
åå¾ããæ å ±ãã.aws/credentialãã«è¿½è¨ãã¾ãã
[temp] aws_access_key_id = ASIA574ÃÃÃÃÃÃÃÃS5UOKBD aws_secret_access_key = Enqe7K7Oj2VKVMÃÃÃÃÃÃÃÃÃÃÃthvYSBf86AO/H aws_session_token = FwoGZXIvYXdzEKX//////////wEaDG4IBEijFDaVHbCUMiKGAYqcEoXb7SEIV7yf3LTuÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃÃp8sLWDg7lj1Ue8jQkWAmZ8/IEtcQDSL88kSY4lExWYBAmMmdbSzkvAeo5fX7np7gPG5O5TxaxFhBCnnI/vbmo7MHZWOo+EqulN0iRm60Y3gbVKJShyJoGMijoyK/mZ/jc2wP4Uoay72yNeJUJcOr5TdZ2uhyf7yTOZomLT9GsE3Xb
ã.aws/configãã«ä¸æèªè¨¼æ å ±ã®profileã追å ãã
ä¸æèªè¨¼ç¨ã® profile ããã.aws/configãã«è¿½è¨ãã¾ãã
[profile temp] region = ap-northeast-1 output = json
移åå OUã®OU IDã確èªãã
AWS Organizationsã®ç»é¢ã§OU IDã確èªãã¾ãããouãããå§ã¾ãæååã§ãã
ã¹ã¯ãªãããå®è¡
äºåæºåãåºæ¥ãããã¹ã¯ãªãããå®è¡ãã¾ãã
ä»åä½æããã¹ã¯ãªãã
ä»åä½æããã¹ã¯ãªããã¯ä»¥ä¸ã§ãã
#!/bin/bash FILE_NAME=./move_account_list.txt DEST_ID=<移åå OUã®OU ID> PROFILE=<ä¸æèªè¨¼ç¨ã®profileã®profileå> while read ACCOUNT do BEFORE_ID=$(aws organizations list-parents --child-id ${ACCOUNT} --profile ${PROFILE} --query 'Parents[].Id' --output text) sleep 5 aws organizations move-account --account-id ${ACCOUNT} --source-parent-id ${BEFORE_ID} --destination-parent-id ${DEST_ID} --profile ${PROFILE} sleep 10 AFTER_ID=$(aws organizations list-parents --child-id ${ACCOUNT} --profile ${PROFILE} --query 'Parents[].Id' --output text) sleep 5 echo "${ACCOUNT},${BEFORE_ID},${AFTER_ID}" >> ./move_result_list.csv done < ${FILE_NAME}
DEST_IDã®å¤ã¯ã¹ã¯ãªããä¸ã«ãã¿æ¸ããã¦ãã¾ãã¾ããããæ¬å½ã¯IDãç´æ¥å
¥ããããªãã®ã§ãããOUåããOU IDãå¼ã£å¼µã£ã¦ããAWS CLIã³ãã³ããç¡ãã£ããããæ³£ãæ³£ããã®ãããªå½¢ãåãã¾ããã
ãããã®ã¹ã¯ãªãããåèã«ãã¦ãå©ç¨ãããå ´åããªã½ã¼ã¹IDãç´æ¥è¨è¿°ããããã¨ãäºããèªèã®ãããåãæ±ãã«ã¯ã注æããã ãããããé¡ããã¾ãã
ã¾ããä»åã¯æ¤è¨¼ãªã®ã§ã¨ã©ã¼ãã³ããªã³ã°ã®å¦çã¯å
¥ãã¦ãã¾ããããèªèº«ã®ç°å¢ã§ãå©ç¨ãããå ´åã¯ãå¿
è¦ã«å¿ãã¦é©å®ãããã£ãå¦çã追å ããã ããã°å¹¸ãã§ãã
ã¹ã¯ãªããã®ä¸èº«è§£èª¬
ããªãã·ã³ãã«ãªã¹ã¯ãªããã§ãããæè§ãªã®ã§ä¸èº«ã解説ãããã¨æãã¾ãã
å¤æ°ã®å®£è¨
FILE_NAME=./move_account_list.txt DEST_ID=<移åå OUã®OU ID> PROFILE=<ä¸æèªè¨¼ç¨ã®profileã®profileå>
å¤æ°ã宣è¨ãã¾ãã
ãFILE_NAMEãã«ã¯ã¢ã«ã¦ã³ããªã¹ãã®ãã¡ã¤ã«ãã¹ãæå®ãã¾ããæ¬ããã°ã§ã¯ã¹ã¯ãªãããã¡ã¤ã«ããã®ç¸å¯¾ãã¹ã§è¨è¼ãã¦ãã¾ãããæå
ã®ç°å¢ã«åããã¦é©å®å¤æ´ãã ããã
ãDEST_IDãã«ã¯ç§»åå
OUã®OU IDãæå®ãã¾ããåè¿°éãããªã½ã¼ã¹IDããã¿æ¸ããã¦ãã¾ã£ã¦ããã®ã§ãæ£ç´ãã¾ãè¯ãæ¸ãæ¹ã¨ã¯è¨ãã¾ãããã
ãPROFILEãã«ã¯ä¸æèªè¨¼ç¨ã®profileã®profileåãæå®ãã¾ããæ¬ããã°ã§ã¯ãtempãã¨ãã¦ãã¾ãã
ç¹°ãè¿ãå¦ç
while read ACCOUNT do ã» ã» ã» done < ${FILE_NAME}
ã¢ã«ã¦ã³ããªã¹ããã1è¡ãã¤ã¢ã«ã¦ã³ãçªå·ãèªã¿è¾¼ã¿å¦çãè¡ãã¾ãã ãªã¹ãã«è¨è¼ããã¦ããã¢ã«ã¦ã³ãæ°åãå¦çãç¹°ãè¿ãã¾ãã
移ååOU IDã®åå¾
BEFORE_ID=$(aws organizations list-parents --child-id ${ACCOUNT} --profile ${PROFILE} --query 'Parents[].Id' --output text) sleep 5
対象ã®ã¢ã«ã¦ã³ãã移ååã«æå±ãã¦ããOUã®OU IDãåå¾ãããBEFORE_IDãã¨ããå¤æ°ã«çµæãæ ¼ç´ãã¦ãã¾ãã
ãaws organizations list-parentãã§ã¯ä»¥ä¸ãµã³ãã«ã®ãããªçµæãå¾ãããã®ã§ãqueryã§OU IDã ããåå¾ãã¦ãã¾ãã
{ "Parents": [ { "Id": "ou-examplerootid111-exampleouid111", "Type": "ORGANIZATIONAL_UNIT" } ] }
æå®ããOUã¸ã®ç§»å
aws organizations move-account --account-id ${ACCOUNT} --source-parent-id ${BEFORE_ID} --destination-parent-id ${DEST_ID} --profile ${PROFILE} sleep 10
ã¡ã¤ã³ã®å¦çã§ããã¢ã«ã¦ã³ããªã¹ãããèªã¿è¾¼ãã ãã¢ã«ã¦ã³ããããDEST_IDãã§æå®ããOUã«ç§»åãã¾ãã
移åå¾ã®OU IDã®ç¢ºèª
AFTER_ID=$(aws organizations list-parents --child-id ${ACCOUNT} --profile ${PROFILE} --query 'Parents[].Id' --output text) sleep 5
移åå¾ã«å度ã¢ã«ã¦ã³ããæå±ãã¦ããOUã®OU IDã確èªãããAFTER_IDãã¨ããå¤æ°ã«æ ¼ç´ãã¦ãã¾ããæ¬æ¥ã§ããã°ããAFTER_IDãã¨ãDEST_IDããæ¯è¼ãã¦ãä¸ä¸è´ãããã°ã¨ã©ã¼å¦çãè¡ãçã®è¨è¿°ããã£ãæ¹ãè¯ãã¨æãã®ã§ãããä»åã¯ã¨ããã³ã¹ã¨ãã¦åå¾ããã«çãã¦ãã¾ãã
CSVã¸ã®åºå
echo "${ACCOUNT},${BEFORE_ID},${AFTER_ID}" >> ./move_result_list.csv
ã¢ã«ã¦ã³ãçªå·ã移ååã®OU IDã移åå¾ã®OU IDãCSVãã¡ã¤ã«ã¸åºåãã¦ãã¾ãã
CSVã®å 容ã¯ä»¥ä¸ãµã³ãã«ã®ããã«ãªãã¾ãã
111111111111,ou-xxxx-aaaaaaaa,ou-xxxx-12345678 222222222222,ou-xxxx-bbbbbbbb,ou-xxxx-12345678 333333333333,ou-xxxx-bbbbbbbb,ou-xxxx-12345678 444444444444,ou-xxxx-cccccccc,ou-xxxx-12345678 ã» ã» ã»
å®è¡çµæ
æå¾ã«ãå®éã«ã¹ã¯ãªãããå®è¡ããçµæã§ãã AWS Organizationsã®ç»é¢ãæ´æ°ããã¨ãä¸å³ã®éããæ³å®éãå ¨ã¦ç§»åããã¦ãã¾ããã
以ä¸ã§ãã移åããã¢ã«ã¦ã³ãã100ãè¶
ãããããªå ´åããã¤ã移ååã®OUããã©ãã©ã®å ´åãããã¸ã¡ã³ãã³ã³ã½ã¼ã«ä¸ã§ç§»åãããã®ã¯æéãªã®ã§ãã¹ã¯ãªããã§ç§»åããã¦ã¿ã¾ãããåããããªç¶æ³ã«ç½®ããã¦ããæ¹ã®åèã«ãªãã°å¹¸ãã§ãã
å±±ä¸ ç¥æ¨¹(å·çè¨äºã®ä¸è¦§)
2021å¹´11æä¸éå ¥ç¤¾ãåè·ã§ã¯æ ã·ã¹ã¨ãã¦ç¤¾å ãããã¯ã¼ã¯ã®æ´æ¹ãéç¨ã«æºãã£ã¦ãã¾ããã 2023 Japan AWS All Certifications Engineersã