1
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?

More than 3 years have passed since last update.

ServerlessFrameworkでAPIGatewayのログを確認する

Last updated at Posted at 2020-05-17

APIGatewayのログ確認方法

まず、CloudWatchのログを有効化する
(providerの配下にlogsを追加)

serverless.yml
service: lambda-demo

provider:
  name: aws
  runtime: python3.8
  region: ap-northeast-1
  stage: ${opt:stage, 'dev'}
  logs:
    restApi:
      role: !Join
              - ''
              - - 'arn:aws:iam::'
                - !Ref "AWS::AccountId"
                - ':role/★★★'  
functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: /
          method: get
          integration: lambda

resources:
  Outputs:
    ApiGatewayRestApiLOGTailCommand:
      Value: !Join
              - ''
              - - 'aws logs tail --follow  API-Gateway-Execution-Logs_'
                - !Ref ApiGatewayRestApi
                - '/${self:provider.stage}'

★★★にはAmazonAPIGatewayPushToCloudWatchLogsのポリシーが付与されたロール名を設定する

以下のIAM画面を参考にしてください。自分でロールを作成する必要があります。
image.png

デプロイしてoutputsを確認

$ sls info -v

Stack Outputs
ApiGatewayRestApiLOGTailCommand: aws logs tail --follow  API-Gateway-Execution-Logs_m32jkcrrq6/dev

# m32jkcrrq6はAPIGatewayのID

awscli2.0以上でaws logs tail --follow API-Gateway-Execution-Logs_m32jkcrrq6/devするとAPIGatewayのログがtailされる

1
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
1
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?