説明
必要な権限が異なる関数には、それぞれに IAM 実行ロールを割り当てます。
想定される影響
共有ロールを使う関数は、別の関数だけが必要とするリソースにアクセスできる場合があります。
対処方法
関数に専用の role を指定するか、関数単位で IAM 権限を設定します。ロールのポリシーは、その関数が使うアクションとリソースに絞ります。
例
hello には、Lambda が引き受けられるロールの ARN を指定します。
変更前
yaml
service: service
frameworkVersion: "4"
provider:
name: aws
runtime: nodejs22.x
functions:
hello:
handler: handler.hello
変更後
yaml
service: service
frameworkVersion: "4"
provider:
name: aws
runtime: nodejs22.x
functions:
hello:
handler: handler.hello
role: arn:aws:iam::123456789012:role/hello-function-role