【小ネタ】Step Functions の HTTP Endpoint は Authorization ヘッダーをサポートしていない

【小ネタ】Step Functions の HTTP Endpoint は Authorization ヘッダーをサポートしていない

Clock Icon2025.04.21

Step Functions には HTTP Endpoint という、Lambda を用意せずともステートマシン内で HTTPS API を呼び出すことができるタスクが用意されています。

stepfunctions_http_endpoint

re:Invent 2023 で発表された機能で、発表時の紹介記事は以下になります。

https://dev.classmethod.jp/articles/update-aws-step-functions-http-endpoint-and-teststate-api/

ただこの HTTP Endpoint にはサポートしていない HTTP ヘッダーがあり、ドキュメントに以下が列挙されています。

You can't use the following headers in your HTTP Task definition.
If you use these headers, the HTTP Task fails with the States.Runtime error.

  • A-IM
  • Accept-Charset
  • Accept-Datetime
  • Accept-Encoding
  • Cache-Control
  • Connection
  • Content-Encoding
  • Content-MD5
  • Date
  • Expect
  • Forwarded
  • From
  • Host
  • HTTP2-Settings
  • If-Match
  • If-Modified-Since
  • If-None-Match
  • If-Range
  • If-Unmodified-Since
  • Max-Forwards
  • Origin
  • Pragma
  • Proxy-Authorization
  • Referer
  • Server
  • TE
  • Trailer
  • Transfer-Encoding
  • Upgrade
  • Via
  • Warning
  • x-forwarded-*
  • x-amz-*
  • x-amzn-*

https://docs.aws.amazon.com/step-functions/latest/dg/call-https-apis.html#unsupported-http-task-responses

今回は上記に Authorization ヘッダーが含まれていないが、実際には使用するとエラーになるよというお話です。

マネジメントコンソールから試してみた

試しに HTTP Endpoint を呼び出す Step Functions を作成します。

create_stepfunctions_http_endpoint

HTTP Endpoint の設定の詳細パラメーターでヘッダーを編集できるので、”Authorization”: “foo” を入力します。

http_endpoint_parameter

そしてこの状態で保存ボタンを押すとエラーが発生します。

ワークフローに 1 件のエラーが見つかりました。

  • /States/InvokeHttpEndpoint/Parameters: The 'Headers' field contains unsupported values: [authorization]

http_endpoint_error

ヘッダーにサポートされていない Authorization を使用したと怒られてしまいます。

CloudFormation から試してみた

以下の CloudFormation テンプレートをデプロイします。

AWSTemplateFormatVersion: "2010-09-09"

Resources:
  ExampleConnection:
    Type: AWS::Events::Connection
    Properties:
      Name: example-conn
      AuthorizationType: API_KEY
      AuthParameters:
        ApiKeyAuthParameters:
          ApiKeyName: dummy-key
          ApiKeyValue: dummy-value

  # IAM Role for Step Functions
  StepFunctionsExecutionRole:
    Type: AWS::IAM::Role
    Properties:
      AssumeRolePolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Principal:
              Service: states.amazonaws.com
            Action: "sts:AssumeRole"
      ManagedPolicyArns:
        - "arn:aws:iam::aws:policy/AWSStepFunctionsFullAccess"
      Policies:
        - PolicyName: EventBridgeConnectionsAccess
          PolicyDocument:
            Version: "2012-10-17"
            Statement:
              - Effect: Allow
                Action:
                  - "events:RetrieveConnectionCredentials"
                  - "events:InvokeConnection"
                Resource: !GetAtt ExampleConnection.Arn
              - Effect: Allow
                Action:
                  - "secretsmanager:GetSecretValue"
                  - "secretsmanager:DescribeSecret"
                Resource: !Sub arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:events!connection/example-conn/*

  # Step Functions State Machine
  ExampleStateMachine:
    Type: AWS::StepFunctions::StateMachine
    Properties:
      RoleArn: !GetAtt StepFunctionsExecutionRole.Arn
      StateMachineType: STANDARD
      Definition:
        StartAt: InvokeHttpEndpoint
        States:
          InvokeHttpEndpoint:
            Type: Task
            Resource: "arn:aws:states:::http:invoke"
            Parameters:
              Authentication:
                ConnectionArn: !GetAtt ExampleConnection.Arn
              Method: "GET"
              ApiEndpoint: "https://dummy.execute-api.ap-northeast-1.amazonaws.com/dummy/"
              Headers:
                Content-Type: "application/json"
                Authorization: "foo"
            End: true

すると CloudFormation 経由でもマネジメントコンソールと同様に以下のエラーが確認できました。

Resource handler returned message: "Invalid State Machine Definition: 'SCHEMA_VALIDATION_FAILED: The 'Headers' field contains unsupported values: [authorization] at /States/InvokeHttpEndpoint/Parameters' (Service: Sfn, Status Code: 400, Request ID: 1aa8b361-1a91-1ab1-1a11-1af5936ff911) (SDK Attempt Count: 1)" (RequestToken: 1aa8b361-1a91-1ab1-1a11-1af5936ff911, HandlerErrorCode: InvalidRequest)

ちなみに API Gateway 統合は

ちなみに Step Functions の API Gateway 統合のドキュメントには以下の記載があり、Authorization ヘッダーは許可されていないと明記されています。

For security considerations, the following HTTP header keys are not currently permitted:

  • Anything prefixed with X-ForwardedX-Amz or X-Amzn.
  • Authorization
  • Connection
  • Content-md5
  • Expect
  • Host
  • Max-Forwards
  • Proxy-Authenticate
  • Server
  • TE
  • Transfer-Encoding
  • Trailer
  • Upgrade
  • Via
  • Www-Authenticate

https://docs.aws.amazon.com/step-functions/latest/dg/connect-api-gateway.html

セキュリティ上の理由としているため、Step Functions の HTTP Endpoint でも同様の理由だと推測できます。そのため今後のアップデートでサポートされるのも期待薄です。

代替案

Authorization ヘッダーの値が固定なら、HTTP Endpoint が使用する EventBridge の Connection の認証設定に入力する方法があります。

eventbridge_connections_setting

ただし JWT など動的に値が変わるなら、素直に Lambda を使う必要があると考えます。

上記の EventBridge の Connection の認証情報が Secret Manager に保存されるなら、「その値を動的に変更すればいい」と考える方もいるかもしれませんが、マネージドシークレットとなりユーザーは編集できないため、この方法を取ることはできません。

もし他に HTTP Endpoint で動的な値を Authorization ヘッダーで送る方法があれば教えてください。

最後に

繰り返しになりますが、Step Functions の HTTP Endpoint は Authorization ヘッダーをサポートしていません。

Step Functions 内から API を呼び出しする仕組みを構築する際に、設計段階で考慮できるように頭の片隅にでも残しておいていただけると幸いです。

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.