0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【AWS】Codebuildエラー「because no identity-based policy allows the lambda」の原因と解決方法

Posted at

概要

Codebuildのbuildspec.yaml内で、ソースコードをLambdaへのアップロードを実施するようにしました。
その際に以下のエラーに遭遇。原因と解決方法を紹介します。

An error occurred (AccessDeniedException) when calling the UpdateFunctionCode operation: User: arn:aws:sts:::assumed-role/CodeBuildRole/AWSCodeBuild-xxxxxxxx is not authorized to perform: lambda:UpdateFunctionCode on resource: arn:aws:lambda:::function: because no identity-based policy allows the lambda:UpdateFunctionCode action

原因

原因は、CodeBuildの実行ロールにlambda:UpdateFunctionCodeアクションを実行するための権限がないため。IAMロールに権限付与が必要です。

解決

CodeBuildの実行ロールに、lambda:UpdateFunctionCodeアクションを許可するポリシーを追加すればOKです。

CodeBuildプロジェクトの「サービスロール」と書いてあるところから該当のIAMロールへ飛べます。

私の場合は、既存で利用していたロールに以下のように追加しました。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:PutLogEvents",
                "s3:PutObject",
                "s3:GetObject",
                "s3:GetObjectVersion",
                "s3:GetBucketAcl",
                "s3:GetBucketLocation",
                "codebuild:CreateReportGroup",
                "codebuild:CreateReport",
                "codebuild:UpdateReport",
                "codebuild:BatchPutTestCases",
                "codebuild:BatchPutCodeCoverages",
                "codebuild:StartBuild",
                "codebuild:StopBuild",
                "codebuild:RetryBuild",
                "lambda:UpdateFunctionCode"  ## これを追加!
            ],
            "Resource": "*"
        }
    ]
}

これにより、
CodeBuildがLambda関数のコードを更新できるようになり、エラーがなくなりました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?