ããã«ã¡ã¯ãAWS CLIã好ããªç¦å³¶ã§ãã
- ã¯ããã«
- CLIã使ã£ãCodeCommitã¸ã®ã¢ã¯ã»ã¹æ¹æ³
- æ¦è¦å³
- åæ
- æé
- â git-remote-codecommitã®å°å ¥(æ¢ã«å°å ¥ããã¦ããå ´åã対å¿ä¸è¦ã§ãã)
- â¡AWS CLIã®å°å ¥(æ¢ã«å°å ¥ããã¦ããå ´åã対å¿ä¸è¦ã§ãã)
- â¢Gitã®å°å ¥(æ¢ã«å°å ¥ããã¦ããå ´åã対å¿ä¸è¦ã§ãã)
- â£Gitã®è¨å®(æ¢ã«è¨å®ããã¦ããå ´åã対å¿ä¸è¦ã§ãã)
- â¤AWS CLIã®Profileã®è¨å®
- â¥git cloneã®å®è¡
- çµããã«
ã¯ããã«
ä»åã¯ãCodeCommitã¸CLIã使ã£ãã¯ãã¹ã¢ã«ã¦ã³ãæ¹æ³ãããã°ã«è¨è¼ãããã¾ãã
CLIã使ã£ãCodeCommitã¸ã®ã¢ã¯ã»ã¹æ¹æ³
ã¾ãåãã«CodeCommitã¸ã®ã¢ã¯ã»ã¹ããæ¹æ³ã¯è¤æ°ããã¾ãããã¯ãã¹ã¢ã«ã¦ã³ãããå ´åã¯1ã¤ã®æ¹æ³ãããããã¾ããã
ãã®ãããä»ã¾ã§ã·ã³ã°ã«ã¢ã«ã¦ã³ãã§éç¨ãã¦ããããã¢ã«ã¦ã³ãã®æ°ãå¢ããã¯ãã¹ã¢ã«ã¦ã³ãããå¿ è¦ãåºã¦ããå ´åã«æ¬ããã°ãåèã«ãªããã¨åãã¾ãã
- ã·ã³ã°ã«ã¢ã«ã¦ã³ã
â Gitã¯ã¬ãã³ã·ã£ã«ãç¨ããã¢ã¯ã»ã¹
â¡å ¬ééµ/ç§å¯éµãç¨ããã¢ã¯ã»ã¹
â¢git-remote-codecommitãå©ç¨ããã¢ã¯ã»ã¹
â£AWS CLIã«å«ã¾ããèªè¨¼æ å ±ãã«ãã¼ãå©ç¨ããã¢ã¯ã»ã¹ - ã¯ãã¹ã¢ã«ã¦ã³ã
â¤IAMãã¼ã«ãå©ç¨ããã¯ãã¹ã¢ã«ã¦ã³ãã¢ã¯ã»ã¹ (æ¬ããã°ã§è¨è¼ããå 容)
âåã¢ã¯ã»ã¹æ¹æ³ã®åè docs.aws.amazon.com
æ¦è¦å³
æ¦è¦å³ã¯ä»¥ä¸ã®éãã§ãã
ä»åã¯ã111111111111ã¨ããAWSã¢ã«ã¦ã³ãã®IAMã¦ã¼ã¶ã¼(ã¯ã¬ãã³ã·ã£ã«)ã使ãã222222222222ã¨ããAWSã¢ã«ã¦ã³ãã«åå¨ããIAMãã¼ã«ã¸ã¹ã¤ãããã¼ã«ããCodeCommitã¸ã¢ã¯ã»ã¹ãããã¾ãã
ãã¤ã³ããªã®ããå³ã«ãè¨è¼ã®éããgit-remote-codecommitã¨ãããã¼ã«ãå¿ è¦ã¨ããç¹ã«ãªããã¨åãã¾ãã â»èªè¨¼æ å ±ãã«ãã¼ã使ããã¨ãå¯è½ãªããã§ãããgit-remote-codecommitã使ããã¨ãæ¨å¥¨ããã¦ãã¾ãã
åæ
- IAMã¦ã¼ã¶ã¼ããã³IAMãã¼ã«ãæ¢ã«ä½ææ¸ã¿ã§ãããã¨
ä½æã§ãã¦ããªãå ´åã¯ã以ä¸ãåèã«ä½æãã¦ãã ããã ä»åã®ä¾ã§ããã¨AccountBã¯111111111111ãAccountAã¯222222222222ã¨ãªãã¾ãã
æé
â git-remote-codecommitã®å°å ¥(æ¢ã«å°å ¥ããã¦ããå ´åã対å¿ä¸è¦ã§ãã)
pipã³ãã³ãã使ããgit-remote-codecommitã®å°å ¥ãã¾ãã
pip install git-remote-codecommit
â»pipãå°å ¥ããã¦ããªãå ´åã以ä¸ãåèã«å°å ¥ãã¾ãã
â¡AWS CLIã®å°å ¥(æ¢ã«å°å ¥ããã¦ããå ´åã対å¿ä¸è¦ã§ãã)
以ä¸ãåèã«AWS CLIãå°å ¥ãã¾ãã
Installing or updating the latest version of the AWS CLI - AWS Command Line Interface
â¢Gitã®å°å ¥(æ¢ã«å°å ¥ããã¦ããå ´åã対å¿ä¸è¦ã§ãã)
以ä¸ã®ã©ã¡ãããåèã«Gitãå°å ¥ãã¾ãã
â£Gitã®è¨å®(æ¢ã«è¨å®ããã¦ããå ´åã対å¿ä¸è¦ã§ãã)
ãªãã¸ããªãã¯ãã¼ã³ãããã£ã¬ã¯ããªã§user.nameããã³user.emailãè¨å®ãã¾ãã
- å®è¡ä¾
git config --local user.name "Kazuya Fukushima" git config --local user.email [email protected]
â¤AWS CLIã®Profileã®è¨å®
- ~/.aws/credentialsã¨ãããã¡ã¤ã«ãä½æãã以ä¸ãè¨å®ãã¾ãã
ãã¡ãã¯æ¦è¦å³ã§ããã¨ããã®ãiam-userãã®ã¯ã¬ãã³ã·ã£ã«æ å ±ãè¨å®ãã¾ãã
[ãä»»æã®åå1ã] aws_access_key_id = ãã¢ã¯ã»ã¹ãã¼IDã aws_secret_access_key = ãã·ã¼ã¯ã¬ããã¢ã¯ã»ã¹ãã¼ã
â»1ããã®ç®æã¯é©åãªå¤ãè¨å®ãã¾ãããä»»æã®åå1ããæãã¤ããªãå ´åãbastionã§è¯ããã¨åãã¾ãã
â»2 ã¯ã¬ãã³ã·ã£ã«ãæã£ã¦ããªãå ´åã以ä¸ãåèã«ä½æãã¦ãã ããã
IAM ã¦ã¼ã¶ã¼ã®ã¢ã¯ã»ã¹ãã¼ã®ç®¡ç - AWS Identity and Access Management
- ~/.aws/configã¨ãããã¡ã¤ã«ãä½æãã以ä¸ãè¨å®ãã¾ãã
[profile ãä»»æã®åå1ã] region = ap-northeast-1 output = json [profile ãä»»æã®åå2ã] region = ap-northeast-1 output = json account = ãã¹ã¤ããå ã®ã¢ã«ã¦ã³ãIDã role_arn = ãã¹ã¤ãããããã¼ã«ã®ARNã source_profile = ãä»»æã®åå1ã mfa_serial = arn:aws:iam::ãã¹ã¤ããå ã®ã®ã¢ã«ã¦ã³ãIDã:mfa/ãIAMã¦ã¼ã¶ã¼åã
â»1ããã®ç®æã¯é©åãªå¤ãè¨å®ãã¾ãã
â»2 mfa_serialã®ç®æã¯ãMFAèªè¨¼ãä¸è¦ãªå ´åãä¸è¦ã§ãã
- è¨å®ä¾
[profile bastion] region = ap-northeast-1 output = json [profile MyCrossAccountAccessProfile] region = ap-northeast-1 output = json account = 222222222222 role_arn = arn:aws:iam::222222222222:role/CodeCommitRole source_profile = bastion mfa_serial=arn:aws:iam::111111111111:mfa/iam-user
以ä¸ã§æºåã¯å®äºã§ãï¼
â¥git cloneã®å®è¡
git clone codecommit://ãä»»æã®åå2ã@ããªãã¸ããªåã
- å®è¡ä¾
git clone codecommit://MyCrossAccountAccessProfile@CrossRepository
ãã®ä»ã®ã³ãã³ãã¯é常ã®gitæä½ã§åæ§ã®æä½ãå¯è½ã§ãã
- å®è¡ä¾
# touch NewFile.txt # # git add NewFile.txt # # git commit -m "Added a file to test cross-account access to this repository" [master a3001ae] Added a file to test cross-account access to this repository 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 NewFile.txt # # git push Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Writing objects: 100% (3/3), 289 bytes | 289.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To codecommit://CrossRepository 765eeb8..a3001ae master -> master #
çµããã«
ä»åã¯ãCodeCommitã¸CLIã使ã£ãã¯ãã¹ã¢ã«ã¦ã³ãæ¹æ³ã«ã¤ãã¦ã¾ã¨ãã¦ã¿ã¾ãããã©ãªããã®ãå½¹ã«ç«ã¦ãã°å¹¸ãã§ãã