$30 off During Our Annual Pro Sale. View Details »

サーバーレスを “安全・安心” に使う / Serverless Security Pattern

kensh
March 06, 2023

サーバーレスを “安全・安心” に使う / Serverless Security Pattern

サーバーレスを使っているとインフラをAWSが管理してくれるので、開発者・運用者目線からは、すでに “安全・安心” が得られていると言えなくもないですが、そんな中でいろんなサービス運用者やプロダクト開発者と会話してきた経験談を基に さらなる “安全・安心” を目指すお話しをさせて頂きます。

kensh

March 06, 2023
Tweet

More Decks by kensh

Other Decks in Technology

Transcript

  1. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    © 2023, Amazon Web Services, Inc. or its affiliates.
    サーバーレスを “安全・安心” に使う
    (パターン集)
    J A W S - U G 札 幌 第 2 9 回 勉 強 会
    Kensuke Shimokawa
    Snr. Serverless Specialist
    Amazon Web Services Japan
    https://speakerdeck.com/_kensh
    https://qiita.com/_kensh

    View Slide

  2. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    © 2023, Amazon Web Services, Inc. or its affiliates.
    About Me…
    Kensuke Shimokawa
    Amazon Web Services Japan
    Snr. Serverless Specialist
    https://speakerdeck.com/_kensh
    https://qiita.com/_kensh

    View Slide

  3. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    © 2023, Amazon Web Services, Inc. or its affiliates.
    “安全・安心” かどうか

    View Slide

  4. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    安全・安心 ってなに?
    5
    安全
    危険がなく安心なこと。傷病などの生命にかかわる心配、
    物の盗難・破損などの心配のないこと。また、そのさま。
    安心
    気にかかることがなく心が落ち着いていること。また、
    そのさま。
    辞書

    View Slide

  5. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    安全と安心を考える
    6
    https://www.soumu.go.jp/johotsusintokei/whitepaper/column_uchida.html
    出典) 総務省有識者コラム

    View Slide

  6. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    © 2023, Amazon Web Services, Inc. or its affiliates.
    おさらいから、、

    View Slide

  7. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    責任共有モデル - Lambda
    8
    https://docs.aws.amazon.com/lambda/latest/dg/lambda-security.html

    View Slide

  8. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    Isolation / 独立環境
    9
    function
    instance
    f(x)=>{ }
    f(x)
    deployment
    g(x)
    request to f(x)
    handling
    cold start

    View Slide

  9. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    Isolation / 独立環境
    10
    function
    instance
    f(x)=>{ }
    f(x)
    deployment
    g(x)
    response from f(x)

    View Slide

  10. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    Isolation / 独立環境
    11
    function
    instance
    f(x)=>{ }
    f(x)
    deployment
    g(x)
    request to f(x)
    handling
    warm start
    request to f(x)
    function
    instance
    f(x)=>{ }
    handling
    cold start
    request to g(x)
    function
    instance
    g(x)=>{ }
    handling
    cold start

    View Slide

  11. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    Isolation / 独立環境
    12
    function
    instance
    f(x)=>{ }
    f(x)
    deployment
    g(x)
    request to f(x)
    handling
    warm start
    request to f(x)
    function
    instance
    f(x)=>{ }
    handling
    cold start
    request to g(x)
    function
    instance
    g(x)=>{ }
    handling
    cold start
    リクエスト単位で Lambdaのinstanceは使いまわされるので、
    たとえば単一のLambda関数を複数のユースケースで再利用していた場合、
    その再利用による memoryからの意図しない漏洩はユーザ側での考慮が必要

    View Slide

  12. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    © 2023, Amazon Web Services, Inc. or its affiliates.
    脆弱性について

    View Slide

  13. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    Amazon Inspector
    14
    • 特徴
    § ワンクリックで有効化
    § リソースの⾃動検出と継続的スキャン
    § ダッシュボードによる容易な脆弱性管理
    § 独⾃含むスコア算出による優先順位付け
    § Organizationとの連携で⼤規模な管理
    § Security Hub, EventBridgeとの連携で検知から対応
    までサポート
    § Amazon EC2, Amazon ECR, AWS Lambda に対応 Amazon EC2 Amazon ECR
    Amazon Inspector
    AWS Lambda
    ソフトウェアの脆弱性や意図しないネットワーク露出領域
    を継続的なスキャンで検知する脆弱性管理サービス

    View Slide

  14. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    © 2023, Amazon Web Services, Inc. or its affiliates.
    コストについて

    View Slide

  15. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    BillingサービスでBudgetを設定して日毎に検知
    16
    意図しない利用額にならないように、
    BillingサービスでBudgetを設定して
    翌日には検知 ( SNS通知など )

    View Slide

  16. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    Compute Optimizer の推奨事項の理解 (1/2)
    17
    メモリが過剰にプロビジョニングされている(Memory over-provisioned)と認識され、
    そのため関数が最適化されていない(Not optimized)と判定

    View Slide

  17. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    Compute Optimizer の推奨事項の理解 (2/2)
    18
    メモリを大きくすると、呼び出しによる予想利用コストが、5.1% 〜 4.6% 削減見込み

    View Slide

  18. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    AWS Lambda Power Tuning によるチューニング
    19
    AWS Lambda Power Tuning は、
    AWS Step Functions を利⽤したステートマシンであり、
    Lambda 関数のコストやパフォーマンスを最適化
    INPUT
    OUTPUT
    128 MB
    256 MB
    512 MB
    1024 MB
    https://github.com/alexcasalboni/aws-lambda-power-tuning
    {
    "lambdaARN": "arn:aws:lambda: snip",
    "powerValues": [128,256, 512, 1024,1536,2048, 3008],
    "num": 1000,
    "payload": { },
    "parallelInvocation": true,
    "strategy": "speed | cost"
    }
    User functions

    View Slide

  19. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    CPU Intensive な処理系
    20
    def lambda_handler(event, context):
    heavy_CPU_job()
    return {
    'statusCode': 200,
    'body': json.dumps(‘CPU worked’),
    }
    コスト = GB秒 x リクエスト件数
    time
    cost
    MB

    View Slide

  20. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    外部 APIコールに依存する処理系
    def lambda_handler(event, context):
    external_API_call()
    return {
    'statusCode': 200,
    'body': json.dumps(‘API worked’),
    }
    コスト = GB秒 x リクエスト件数
    time
    cost
    MB
    21

    View Slide

  21. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    © 2023, Amazon Web Services, Inc. or its affiliates.
    デプロイについて

    View Slide

  22. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    Lambdaのトラフィックシフト機能
    23
    AWS Lambda
    Alias: prod 新


    Lambda エイリアスに 2 つの関数バージョ
    ンを指定して、各バージョンにルーティン
    グされるトラフィックの割合を設定できる

    View Slide

  23. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    Lambdaのトラフィックシフト機能
    24
    AWS SAM を使用してLambda関数を更新する場合、CodeDeploy が組み込まれているため、
    Lambda関数を線形にデプロイ可能
    https://docs.aws.amazon.com/ja_jp/serverless-application-model/latest/developerguide/automating-updates-to-serverless-apps.html
    HelloFunction:
    Type: AWS::Serverless::Function
    Properties:
    Runtime: python3.9
    Handler: index.handler
    AutoPublishAlias: !Ref Stage
    DeploymentPreference:
    Enabled: true
    Type: Linear10PercentEvery1Minute

    View Slide

  24. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    API Gatewayのカナリアリリース
    25
    リクエスト



    Amazon API Gateway
    ステージに対して「Canary」を定義する
    と、APIの「デプロイ」操作でそのステー
    ジを指定した際に一旦Canary に対しての
    みデプロイされるようになる(メインの内
    容は変わらない)
    Canaryに対して以下の操作が可能:
    • 昇格
    • Canaryのデプロイ内容をメインのステージに
    反映
    • 削除
    • Canaryを削除して、メインステージのみの構
    成に戻す

    View Slide

  25. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    API Gatewayのカナリアリリース
    26
    AWS SAM を使用してAPI Gateway REST APIを更新デプロイする場合は、
    カナリアの設定を組込めるため、ステージに安全にデプロイ可能
    HelloWorldApi:
    Type: AWS::Serverless::Api
    Properties:
    StageName: !Ref StageName
    CanarySetting:
    PercentTraffic: 10
    UseStageCache: false
    https://docs.aws.amazon.com/ja_jp/apigateway/latest/developerguide/canary-release.html

    View Slide

  26. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    AWS AppConfig によるロジックと設定の分離
    27
    デプロイ戦略
    • ベータ環境や本番環境などの論理的な
    デプロイグループを管理可能
    • 論理環境ごとに Amazon CloudWatch アラームを設
    定し AppConfig によってモニタリングすることが可
    能で、デプロイ中にアラームが発生するとロール
    バックをトリガー (設定値のValidationも可能)
    • アプリケーションからは AppConfig の
    GetConfiguration APIでパラメータを取得できるた
    め、 関数インスタンスごとにユニークなClientIDを
    振っておけば自動的に戦略に沿ったカナリアが実現
    • 設定用と関数本体用にCICDパイプラインを分離し2
    つ用意する
    • ここでの設定とはLambda サービスの設定では
    なく、アプリケーション内のロジックにおける
    設定のこと (例. フィーチャーフラグ on/off)
    AWS AppConfig
    https://aws.amazon.com/jp/blogs/news/safe-deployment-of-application-configuration-settings-with-aws-appconfig/
    AWS Lambda



    初期化時に取得し
    TTL付きキャッシュ
    しておく
    Pull
    Pull
    初期化時に取得し
    TTL付きキャッシュ
    しておく
    Parameter Storeなど
    Parameter Storeなど

    View Slide

  27. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    © 2023, Amazon Web Services, Inc. or its affiliates.
    観測について

    View Slide

  28. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    embedded metric format / 埋め込みメトリクスフォーマット
    29
    {
    "_aws": {
    "CloudWatchMetrics": [
    {
    "Dimensions": [ [ "functionVersion" ] ],
    ...
    }
    ]
    },
    "functionVersion": "$LATEST"
    }
    https://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/monitoring/Clo
    udWatch_Embedded_Metric_Format_Specification.html
    CloudWatch 埋め込みメトリクスフォーマットは、
    • 構造化ログイベントに埋め込まれたメトリクス値を
    自動的に抽出するように CloudWatch Logs に指示す
    るために使用される JSON 仕様

    View Slide

  29. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    embedded metric format
    30
    Amazon
    API Gateway
    Mobile client
    Amazon
    CloudWatch Logs
    AWS
    Secrets Manager
    Amazon
    Aurora
    AWS Lambda
    Amazon
    CloudWatch Metrics
    ⾃動的
    ⾮同期
    embedded metric format 標準出⼒
    CloudWatch 埋め込みメトリクスフォーマットは、
    • 構造化ログイベントに埋め込まれたメトリクス値を
    自動的に抽出するように CloudWatch Logs に指示す
    るために使用される JSON 仕様

    View Slide

  30. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    embedded metric format
    31
    from aws_embedded_metrics import metric_scope
    @metric_scope
    def lambda_handler(event, context, metrics):
    results = conn.runQuery(sql)
    metrics.set_namespace("Summit2022")
    metrics.put_dimensions({"dim": "sales"})
    metrics.put_metric("Conversion", results.Count, "Count")
    {
    "LogGroup": "embedded-log",
    (snip)
    "_aws": {
    "Timestamp": 1645369641214,
    "CloudWatchMetrics": [
    {
    "Dimensions": [["LogGroup",
    ”ServiceName", "ServiceType", "dim" ]],
    "Metrics": [{
    "Name": "Conversion",
    "Unit": "Count”
    }],
    "Namespace": "Summit2022"
    }
    ]
    },
    "Conversion": 100
    } Amazon
    CloudWatch Logs
    CloudWatch Logs に標準出⼒

    View Slide

  31. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates. 32

    View Slide

  32. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    embedded metric format
    33
    {

    "lambda_function_name":..,
    "lambda_function_memory_size": 128,
    "lambda_function_arn": ”…",
    "lambda_request_id": "52fd..",
    "message": ”Aha",
    "cold_start": true
    }
    Result
    デコレータで関数Context情報も出力可能

    View Slide

  33. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    カスタムメトリックの出力
    34
    Result ビジネスKPIを可視化!

    View Slide

  34. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    コールドスタートログのみを抽出 (CloudWatch Logs Insights)
    35

    View Slide

  35. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    分散トレースを使用 (AWS X-Ray)
    36
    X-Ray を使用すると、フロントエンド API からバ
    ックエンドのストレージとデータベースまで、ア
    プリケーション内のリソースを横断する際にリク
    エストをトレースできます

    View Slide

  36. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    トレース / サービスマップ
    37
    デコレータでサブセグメントも定義

    View Slide

  37. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    トレース / サービスマップ
    38
    関数セグメントを拡張して、そのサブセグメントを表示

    View Slide

  38. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    AWS Lambda Extensions
    39
    Lambda Extensionsは、Lambdaをお気に入りの監視、セキュリティツールおよびガバナ
    ンスツールと簡単に統合する新しい方法です

    View Slide

  39. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    Lambda Insights Performance monitoring
    40
    Lambda Insights

    View Slide

  40. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    Lambda Concurrency Hunt でスパイクを発見
    41
    過去7日間のMetricsに対して
    同時実行数が最も高い期間
    を見つけ、そのSpikeの前の
    6分間の情報を出力する。
    • 関数の呼び出し回数
    • 平均処理時間
    • 同時実行数
    $ curl https://raw.githubusercontent.com/aws-samples/aws-lambda-concurrency-hunt/master/lambda-con-hunt.py -o lambda-con-hunt.py
    $ python3 lambda-con-hunt.py
    ※ Lambdaの1 分間隔Metricsにおいて、15 日間は
    1 分の分解能を持つ。以降も使用可能だが、5 分に
    集約された分解能となる
    https://aws.amazon.com/jp/cloudwatch/faqs/
    Concurrency Hunt

    View Slide

  41. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    © 2023, Amazon Web Services, Inc. or its affiliates.
    通信について

    View Slide

  42. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    リソースポリシー
    43
    API
    Gateway
    AWS Lambda
    AWS Cloud
    {
    "Version": "2012-10-17",
    "Id": "default",
    "Statement": [{
    "Sid": ”123456c7-a198-4b2d-b5fc-57fb5fefa0e8",
    "Effect": "Allow",
    "Principal": {"Service": "apigateway.amazonaws.com"},
    "Action": "lambda:InvokeFunction",
    "Resource": ”LambdaFunctionARN",
    "Condition": {
    "ArnLike": {
    "AWS:SourceArn": ”sourceServiceARN"
    }
    }
    }]
    }
    {
    "Version": "2012-10-17",
    "Statement": [{
    "Effect": "Allow",
    "Principal": "*",
    "Action": "execute-api:Invoke",
    "Resource": "execute-api:/*/*/*"
    },{
    "Effect": "Deny",
    "Principal": "*",
    "Action": "execute-api:Invoke",
    "Resource": "execute-api:/*/*/*",
    "Condition": {
    "NotIpAddress": {"aws:SourceIp": ["sourceIpOrCIDRBlock”]}
    }
    }]
    }

    View Slide

  43. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    VPC Lambdaについて
    • VPCリソースへのアクセスに、Lambda関数をVPC接続設定する必
    要がある
    • VPC Lambdaはデフォルトでインターネットアクセスがない
    • インターネットアクセスするためには
    • Public Subnet に NAT Gateway を設置
    • Internet Gateway を VPC に設置
    • Route Table でインターネットへの経路を追加
    44

    View Slide

  44. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    VPC Lambdaについて
    • VPC Lambdaはデフォルトでリージョナルサービスへのアクセス
    がない
    • リージョナルサービスへアクセスするには (以下のいずれかが必要)
    • インターネットへの経路を確保
    • サービスごとの VPC Endpoint を利用
    45

    View Slide

  45. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    ネットワークトラフィックを制御する
    46
    Private subnet
    Customer VPC
    AWS Cloud
    AWS Lambda Service VPC
    AWS Lambda
    実行環境
    リージョナルサービス
    Amazon DynamoDB Amazon SNS
    Hyperplane
    NAT
    ENI
    Security Group
    Amazon SQS
    VPC Endpoint
    ENI
    VPC Endpoint
    Gateway
    Route table
    VPC Endpoint
    ENI
    インターネットへのアクセスなし

    View Slide

  46. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    VPC接続を強制し、他VPCにも接続不可とする制御
    47
    {
    "Version": "2012-10-17",
    "Statement": [
    {
    "Sid": "Stmt159186333251",
    "Action": [
    "lambda:CreateFunction",
    "lambda:UpdateFunctionConfiguration"
    ],
    "Effect": "Deny",
    "Resource": "*",
    "Condition": {
    "ForAllValues:StringNotEquals": {
    "lambda:VpcIds": [
    "vpc-0eebf3d0fe63a2db1"
    ]
    }
    }
    }
    ]
    }
    IAM User
    AWS Lambda
    CreateFunction
    or
    UpdateFunctionConfiguration
    Private subnet
    VPC ( vpc-X )
    ENI
    VPCに未接続、または指定
    したVPC以外に接続しよう
    とするとエラーとなる

    View Slide

  47. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    © 2023, Amazon Web Services, Inc. or its affiliates.
    シークレットについて

    View Slide

  48. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    コードで使用される機密情報を安全に保管する
    49
    VPC
    Private subnet
    AWS Secrets Manager
    AWS Lambda
    シークレット
    ローテーション
    Amazon Aurora
    AWS Key Management
    Service
    Role
    暗号化用の
    KMS鍵
    Resource
    Policy
    シークレット情報取得
    シークレット情報を取得
    可能なVPCを制限
    シークレット情報を取得
    可能なIAM Role
    from aws_lambda_powertools.utilities import parameters
    def handler(event, context):
    # Retrieve a single secret
    value = parameters.get_secret("my-secret")
    コード内のハードコードされた認証情報
    (パスワードを含む) を Secrets Manager
    への API コールで置き換えて、プログラ
    ムでシークレットを安全に利用すること
    ができます

    View Slide

  49. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    © 2023, Amazon Web Services, Inc. or its affiliates.
    リクエスト検証 について

    View Slide

  50. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    API Gateway REST API のリクエスト検証
    51
    リクエスト
    Amazon API Gateway
    モデル
    モデル
    モデル
    {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "User",
    "type": "object",
    "properties": {
    "UserID": { "type": "string" },
    "Name": { "type": "string" },
    "Age": {
    "description": "Age in years",
    "type": "integer",
    "minimum": 18
    }
    },
    "required": ["UserID", "Name"]
    }
    application/json
    {
    "UserID": "U0001",
    "Name": "Jhon",
    "Age": 23
    }
    HTTP Body
    検証
    • リクエストボディはコンテンツタイプとモデル
    のセットで検証可能。
    • JSON形式のボディであれば、 application/json
    を設定し、モデルについてはJSON Schema
    draft4形式で各JSONのプロパティに対して検
    証実施
    JSON Schema draft4

    View Slide

  51. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    © 2023, Amazon Web Services, Inc. or its affiliates.
    スロットリング について

    View Slide

  52. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    API Gatewayによるスロットリング制御
    • 閾値を超えるとHTTP 429(Too Many Requests)エラー
    • リトライ実装はAPIクライアント開発者の責務
    • Rate/Burstによるスロットリング設定が可能
    • 使用量プランを使うと
    • Quota(呼び出し回数制限)の設定が可能
    • (日/週/月あたりのリクエスト回数)
    53

    View Slide

  53. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    API Gatewayによるスロットリング制御
    54
    EC2上の
    エンドポイント
    AWS
    Lambd
    a
    AWSサービス
    インターネット
    リソース
    API
    Gateway
    使用量プランThrottling設定 (任意) サーバー側Throttling設定
    メソッド x RESTリソース
    API x ステージ
    アカウント x リージョン
    API x ステージ (default)
    Rate: 10000rps
    Burst 5000req
    Rate: ( ) rps
    Burst ( ) req
    緩和可能
    Rate: ( ) rps
    Burst ( ) req
    Rate: ( ) rps
    Burst ( ) req
    使用量プランを
    設定したリクエスト
    使用量プランを
    設定していないリクエスト
    Quota
    呼び出し回数制限
    ※ThrottlingとQuota制限は、使用プランのすべての API ステージ
    について集約される個々の API キーのリクエストに適用されます
    x-api-key: A
    x-api-key: B
    x-api-key: C

    View Slide

  54. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    © 2023, Amazon Web Services, Inc. or its affiliates.
    ダウンストリーム保護 について

    View Slide

  55. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    スケーラブルではないリソースを保護
    56
    オンプレミスサーバーや永続層などサーバーレス に対応するスケーラビリティが見込まれないダウ
    ンストリームへのアクセスについては、直接行うのではなく、キューやストリーム等のバッファリン
    グによって受け取るトランザクションの数を抑制することでコンポーネントスループットを調整
    AWS Lambda
    Amazon API Gateway
    Amazon
    Simple Queue Service
    SQS イベントに対する同時実行数を
    小さくしておく
    Corporate
    data center
    オンプレミス
    サーバー
    ダウンストリームで
    処理可能な量を処理

    View Slide

  56. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    Lambda の イベントソースで最大同時実行数設定
    57

    View Slide

  57. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    © 2023, Amazon Web Services, Inc. or its affiliates.
    まとめ

    View Slide

  58. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    まとめ
    コスト最適化、カナリアデプロイ、セキュリティ、ダウンストリーム
    保護など様々な観点でユーザーを守る仕組みがあります。
    ぜひ、明日から開発者が安全・安心に利用できるように!
    懇親会であれもこれもという話があれば声をかけてください^^
    59

    View Slide

  59. サーバーレスを “安全・安心” に使う
    © 2023, Amazon Web Services, Inc. or its affiliates.
    © 2023, Amazon Web Services, Inc. or its affiliates.
    Thank you!

    View Slide