LoginSignup
13
9

More than 5 years have passed since last update.

Serverless Framework で iamRoleStatements を設定する

Posted at

概要

serverless framework のデフォルトのserverless.ymlには、↓のようにコメントアウトされて記載されている。


# you can add statements to the Lambda function's IAM Role here
#  iamRoleStatements:
#    - Effect: "Allow"
#      Action:
#        - "s3:ListBucket"
#      Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ]  }
#    - Effect: "Allow"
#      Action:
#        - "s3:PutObject"
#      Resource:
#        Fn::Join:
#          - ""
#          - - "arn:aws:s3:::"
#            - "Ref" : "ServerlessDeploymentBucket"
#            - "/*"

しかしこれって何を意味していてどう書けばいいの?となって困ったので解決の流れと最終的なコードをまとめる。

本編

やりたかったことは、lambda から lambda を呼ぶ InvokeFunction を特定の role に対して許可すること。

調べたら、公式に書いてあったのだが、これだけだと十分にわからなかった。
しかし、こんな質問もあったので、合わせて見てみたら理解できた。

こんな感じで書いて解決した。

provider:
  name: aws
  runtime: nodejs6.10

  #you can overwrite defaults here
  #stage: dev
  region: ap-northeast-1

# you can add statements to the Lambda function's IAM Role here
  iamRoleStatements:
   - Effect: "Allow"
     Action: "lambda:InvokeFunction"
     Resource: "arn:aws:lambda:ap-northeast-1:xxxxxxxxxxxx:function:myServiceHoge-dev-invoke_hello" # InvokeFunction を呼ぶ lambda
13
9
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
13
9