4
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 5 years have passed since last update.

Serverlessでオーソライザーを複数のLambdaから使うための設定方法

Last updated at Posted at 2018-08-03

本記事について

Serverless Framework を使ってLambdaをデプロイする時、オーソライザーを複数のLambdaから使えるようにするための設定について記載

手順

公式マニュアルに記載の通り、オーソライザーを使う全てのhttpイベントにおいて、resultTtlInSeconds: 0を記載する

全てに記載しないとオーソライザーのキャッシュが無効にならないので注意

serverless.yml
functions:
  create:
    handler: posts.create
    events:
      - http:
          path: posts/create
          method: post
          authorizer:
            name: authorizerFunc
            resultTtlInSeconds: 0

解説

オーソライザーのキャッシュが有効になっていると、複数のhttpイベントからオーソライザーが呼び出された際、httpイベントが異なっても他のhttpイベントのキャッシュが参照されてしまうので、オーソライザーのキャッシュは無効にしておかなければいけない。

Serverless Frameworkにおいて、オーソライザーのキャッシュの無効化は、上記の手順で行う。
1つでもresultTtlInSeconds: 0設定が抜けると、キャッシュが設定されてしまうので注意。

本来、API Gatewayのオーソライザーのキャッシュの設定は、オーソライザーの定義箇所で行うが、Serverless Frameworkでは、オーソライザーの定義箇所での設定は行えず(AuthorizerResultTtlInSeconds・resultTtlInSecondsを記述しても効かない)、httpイベントの設定状況から自動で設定されてしまう。

元記事

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