JSON Brody
JSON Brody

Reputation: 828

AWS::Serverless::HttpApi OpenAPI definition with http integration

I have the following AWS::Serverless::HttpApi defined:

MyApi:
    Type: AWS::Serverless::HttpApi
    Properties:
      CorsConfiguration:
        AllowOrigins:
          - http://localhost:3000
          - https://localhost:3000
          - https://my.site
      Domain:
        CertificateArn: !Ref MahCert
        DomainName: api.my.site
        EndpointConfiguration: REGIONAL
        Route53:
          # Very similar to one of the record sets in the R53 record set groups
          DistributionDomainName: !GetAtt CloudFrontCDN.DomainName
          HostedZoneId: !Ref MyHostedZone
          IpV6: true
      StageName: Prod
      DefinitionBody:
        openapi: "3.0.1"
        info:
          title: api.my.site
        paths:
          /steam/hours:
            get:
              responses:
                "200":
                  description: "200 response"
                  headers:
                    Access-Control-Allow-Origin:
                      schema:
                        type: "string"
                  content: { }
              x-amazon-apigateway-integration:
                type: "http"
                httpMethod: "GET"
                uri: "https://example.com"
                responses:
                  default:
                    statusCode: "200"
                    responseParameters:
                      method.response.header.Access-Control-Allow-Origin: "'*'"
                passthroughBehavior: "when_no_match"

      AccessLogSettings:
        DestinationArn: !GetAtt CloudWatchLogGroup.Arn
        Format: '{ "$context.requestId": { "error": { "message": "$context.error.message", "messageString": "$context.error.messageString", "responseType": "$context.error.responseType" }, "integrationError": { "message": "$context.integrationErrorMessage", "error": "$context.integration.error", "status": "$context.integration.status" }}}'

This OpenAPI definition is supposed to define a route with an HTTP integration that proxies requests to https://example.com. I actually exported this OpenAPI spec from a REST API that I built manually. I don't get any issues from CloudFormation about missing properties.

When I try to hit the route, I get a 404. The reason is that there isn't actually any integration attached to this route: enter image description here

Why isn't CloudFormation applying the http integration here?

Upvotes: 1

Views: 635

Answers (1)

GSSwain
GSSwain

Reputation: 6133

The HttpApi on AWS Gateway does not support the HTTP custom integration. It does support the HTTP_PROXY integration. Here is the documentation. The Rest APIs support both HTTP and HTTP_PROXY integrations.

To add a HTTP_PROXY integration, here is how the template would look like for the /steam/hours GET operation.

paths:
  /steam/hours:
    get:
      x-amazon-apigateway-integration:
        type: "http_proxy"
        httpMethod: "GET"
        uri: "https://example.com"
        payloadFormatVersion: "1.0"

Upvotes: 1

Related Questions