LoginSignup
0
0

serverless v4 でAPI Gatewayのログ出力を設定するとエラーになってデプロイできない

Last updated at Posted at 2024-06-29

はじめに

serverless framework v4でAPI Gatewayのログを設定すると、The role with name serverlessApiGatewayCloudWatchRole cannot be found. というエラーが出てデプロイできない不具合がありました。serverlessApiGatewayCloudWatchRoleという名前でIAM Roleを作れば解決するのですが、初見殺しすぎるので解決方法を共有します。

事象

以下のようにserverless.ymlでAPI Gatewayのログを出力するように設定します。

provider:
  name: aws
  logs:
    websocket: true

これでsls deployをすると、以下のエラーが出て、デプロイに失敗します。

✖ An error occurred: CustomApiGatewayAccountCloudWatchRole - Received response status [FAILED] from custom resource. Message returned: The role with name serverlessApiGatewayCloudWatchRole cannot be found. See details in CloudWatch

解決策

serverlessApiGatewayCloudWatchRoleという名前のIAM Roleを作成します。
一度IAM Roleを作成すれば、そのAWSアカウント内では大丈夫です。

作成するIAM Role

以下の設定でIAM Roleを作成します。

  • 信頼されたエンティティタイプ = AWSのサービス
  • サービスまたはユースケース = API Gateway
  • ユースケース = API Gateway

iam-role-config.png

許可ポリシーにAmazonAPIGatewayPushToCloudWatchLogsがデフォルトで選択されているので、そのまま次へをクリック。

スクリーンショット 2024-06-29 18.28.09.png

ロール名にserverlessApiGatewayCloudWatchRoleを入力して、ロールを作成する。

スクリーンショット 2024-06-29 18.29.45.png

参考文献

API Gateway で「CloudWatch Logs role ARN must be set in account settings to enable logging」が発生するときの対処方法
https://dev.classmethod.jp/articles/tsnote-apigw-what-to-do-when-cloudwatch-logs-role-arn-must-be-set-in-account-settings-to-enable-logging-occurs-with-api-gateway/

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