Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
12
Help us understand the problem. What is going on with this article?
@NaokiIshimura

【備忘録】CodeBuildで`aws ecr get-login`コマンド実行時にエラーが発生する

More than 1 year has passed since last update.

問題点

CodeBuildでaws ecr get-loginコマンド実行時にエラーが発生する

ビルド結果

codebuild03.png

buildspec.yml(抜粋)

buildspec.yml
version: 0.2

phases:
  pre_build:
    commands:
    - # 省略
    - $(aws ecr get-login --no-include-email --region ${AWS_DEFAULT_REGION})
    - # 省略

ビルドログ(抜粋)

[Container] 2018/08/23 06:59:56 Running command $(aws ecr get-login --no-include-email --region ${AWS_DEFAULT_REGION})

An error occurred (AccessDeniedException) when calling the GetAuthorizationToken operation: User: arn:aws:sts::xxx:assumed-role/code-build-xxx-xxx-build-service-role/AWSCodeBuild-xxx-xxx-xxx-xxx-xxx is not authorized to perform: ecr:GetAuthorizationToken on resource: *

[Container] 2018/08/23 06:59:57 Command did not exit successfully $(aws ecr get-login --no-include-email --region ${AWS_DEFAULT_REGION}) exit status 255
[Container] 2018/08/23 06:59:57 Phase complete: PRE_BUILD Success: false
[Container] 2018/08/23 06:59:57 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: $(aws ecr get-login --no-include-email --region ${AWS_DEFAULT_REGION}). Reason: exit status 255

原因

ビルドを実行するロールにECRの操作を許可するポリシーがアタッチされてない

解決方法

ビルドを実行するロールにECRを操作を許可するポリシーをアタッチする

1. ビルドで利用してるロールを確認する

CodeBuildのブロジェクト詳細でビルドに利用しているロール名を確認

codebuild01.png

2. IAMでロールにポリシーをアタッチする

IAMでロールにAmazonEC2ContainerRegistryPowerUser(ECRの操作を許可する)ポリシーをアタッチする。

codebuild02.png

3. ビルドが成功するようになったことを確認する

codebuild04.png

12
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
NaokiIshimura
Ruby on Rails Engineer.

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
12
Help us understand the problem. What is going on with this article?