3

jwt オーソライザー ラムダ関数のポリシー サイズに問題があるため、代わりにワイルドカード (*) を使用してポリシーを生成する構成 serverless.yml ファイルでポリシー サイズを縮小したいと考えています。serverless.yml のすべての関数にグローバルオーソライザーを設定できますか?

リソースベースのポリシーの例を次に示します

 {
      "Sid": "1",
      "Effect": "Allow",
      "Principal": {
        "Service": "apigateway.amazonaws.com"
      },
      "Action": "lambda:InvokeFunction",
      "Resource": "arn:aws:lambda:ap-southeast-1-jwtAuthorizer",
      "Condition": {
        "ArnLike": {
          "AWS:SourceArn": "arn:aws:execute-api:ap-southeast-1-abcdefg123"
        }
      }
    },
    {
      "Sid": "2",
      "Effect": "Allow",
      "Principal": {
        "Service": "apigateway.amazonaws.com"
      },
      "Action": "lambda:InvokeFunction",
      "Resource": "arn:aws:lambda:ap-southeast-1-jwtAuthorizer",
      "Condition": {
        "ArnLike": {
          "AWS:SourceArn": "arn:aws:execute-api:ap-southeast-1-abcdefg456"
        }
      }
    },

こんな風に変えたい。

{
      "Sid": "1",
      "Effect": "Allow",
      "Principal": {
        "Service": "apigateway.amazonaws.com"
      },
      "Action": "lambda:InvokeFunction",
      "Resource": "arn:aws:lambda:ap-southeast-1-jwtAuthorizer",
      "Condition": {
        "ArnLike": {
          "AWS:SourceArn": "arn:aws:execute-api:ap-southeast-1-*"
        }
      }
    }

serverless.yml ファイルの例。機能ごとにオーソライザーを設定しています。グローバルに変更したい。

functions:
  searchByProvince:
    handler: handler.searchByProvince
    reservedConcurrency: 10
    events:
      - http:
          path: /
          method: get
          cors:
            origin: "*"
          authorizer:
            arn: arn:aws:lambda:${self:provider.region}:${self:custom.accountId}:jwtAuthorizer

  province:
    handler: handler.province
    reservedConcurrency: 10
    events:
      - http:
          path: /provinces
          method: get
          cors:
            origin: "*"
          authorizer:
            arn: arn:aws:lambda:${self:provider.region}:${self:custom.accountId}:-${self:provider.stage}-jwtAuthorizer

4

0 に答える 0