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?

OCI API Gateway ルート数上限の話

Last updated at Posted at 2025-03-24

はじめに

OCI API Gateway には、デプロイメントごとのルート数が 50個までという制限があります。

参考: APIゲートウェイの内部制限

API設計時にはこの制限を考慮しておらず、機能追加の段階でルート数制限の存在を知りました。
新しいエンドポイントを追加しようとした際、この制約に直面、回避策を検討する必要がありました。

ルート数制限への対応策

この制限に対処するために、様々な選択肢を検討しましたが、最終的にバックエンドサービスに登録しているファンクションのエントリーポイントでルーティングを行う方式を採用しました。

[Client] → [OCI API Gateway] → [OCI Function (エントリーポイント)] → [OCI Function (各モジュール)]

デプロイメントのルート設定

まず、デプロイメントのルート設定を以下のように設定しました。

  • パス: /{wildcard_path*}
  • メソッド: GET, POST, PUT, DELETE
  • バックエンドタイプ: Oracleファンクション

エントリーポイントであるファンクションのサンプル

Python
import io
from urllib.parse import urlparse

import oci
from fdk.response import Response  
from fdk.context import InvokeContext

import apps.getUsers as getUsers
import apps.postUser as postUser

def handler(ctx: InvokeContext, data: io.BytesIO = None) -> Response:
    requestUrl = ctx.RequestURL()
    parsedUrl = urlparse(requestUrl)

    if ctx.Method() == "GET":
        if parsedUrl.path == "/v1/users":
            result = getUsers.handler(ctx, data)
            return result

    if ctx.Method() == "POST":
        if parsedUrl.path == "/v1/users":
            result = postUser.handler(ctx, data)
            return result

まとめ

OCI API Gateway のルート数制限に対応するために、エントリーポイントファンクションを活用したルーティング方式を採用しました。

この方式は、新しいエンドポイントを簡単に追加できるという利点があります。
しかし、コードの複雑化や単一障害点になる可能性といった課題もあるため、適切な設計と運用が求められます。

反省点

今回の対応では、エントリーポイントのファンクションを自作しルーティングを行いましたが、事前に適切な API 設計を行っていればこの問題を回避できた可能性があります。

また、ライブラリやフレームワークを活用すれば、よりシンプルでメンテナンスしやすい実装ができていたかもしれません。

今後の開発では、より柔軟な設計を事前に検討していきたいと考えています。

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?