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】Cloudformationでエラー「The role defined for the function cannot be assumed by Lambda.」が出た場合

Posted at

概要

Cloudformationテンプレートを更新したら以下のエラーが出た。

The role defined for the function cannot be assumed by Lambda.

原因と解決方法

  SampleFunciton:
    Type: AWS::Lambda::Function
    Properties:
      FunctionName: SampleFunciton
      Handler: lambda_handler.handler
      Role: !GetAtt LambdaRole.Arn
      Runtime: python3.12
      # 以下略

上記のようにしていたので、普通であれば、CloudFormationが自動的に依存関係を解決するはず。
しかし、なぜかIAMロールが先に作られず、Lambda関数が先に作成されようとしたため、上記のエラーになったと思われます。

IAMロールの作成が終わってからこっちやってね、ということを明示的に伝える方法としてDependsOnをつける手法があります。これにより、エラーはなくなり、正常に作成されることを確認しました。

とはいえ、普段はDependsOnなくてもエラーなく作成できていましたし、100%起きることではなさそう。
なぜこのようになったのかは不明です。。

一応stackoverflowにも似たような答えを発見。

Make sure the role is completed first by using "DependsOn" and use the intrinsic function """{ "Fn::GetAtt" : [ "your-role-logical-name", "Arn" ] }"""
https://stackoverflow.com/questions/36419442/the-role-defined-for-the-function-cannot-be-assumed-by-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?