SAMで作成されるApiGatewayをエッジ最適化以外で作成したいとき


SAMだとApiGatewayのリソースを書かなくても暗黙的につくられますが、既定ではエッジ最適化でつくられているので、リージョンとかプライベートでつくりたい。
今回はリージョンで指定します。

AWS::Serverless::Api のリソースを記述して、 EndpointConfigurationREGIONAL を指定します。
AWS::Serverless::Function のEventsに Type: Api を作成しますが、その際に RestApiId を指定して、先ほど作成したAWS::Serverless::Api リソースを参照するように指定します。

template.yaml
Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      EndpointConfiguration: REGIONAL
  FooFunction:
    Type: AWS::Serverless::Function
    Properties:
      Events:
        Foo:
          Type: Api
          Properties:
            Path: /foo
            Method: post
            RestApiId: !Ref ApiGatewayApi

参考