【问题标题】:Connect aws WebSocket api to custom domain name将 aws WebSocket api 连接到自定义域名
【发布时间】:2020-11-02 18:15:53
【问题描述】:

我使用 aws WebSocket api 创建了一个消息传递应用程序,并使用无服务器进行了部署。 API 已成功部署,我可以使用 wscat 测试这些 API。我在堆栈中也有其他 Rest api。我尝试将我的新 WebSocket api 堆栈映射到现有域名,但收到错误:Only REGIONAL domain names can be managed through the API Gateway V2 API. For EDGE domain names, please use the API Gateway V1 API. Also note that only REST APIs can be attached to EDGE domain names.

我被困住并试图弄清楚要进行哪些更改。

我浏览了https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-api.htmlhttps://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html,但无法弄清楚。

【问题讨论】:

    标签: amazon-web-services websocket aws-api-gateway serverless-framework


    【解决方案1】:

    can't mix API Gateway mapping between RestApis and Websocket APIs 在单个自定义域下。换句话说,就是说我们不能为 RestAPI 和 WebSocket 使用同一个域或子域。

    为 WebSocket 映射创建自定义域时应注意的几件事

    1. WebSocket 不支持边缘优化的自定义域端点
    2. WebSocket 安全策略仅允许 TLS 1.2,不允许 TLS 1.0
    3. 除非像 RestApi 自定义域引用,否则不能从其他区域引用域证书

    如何在云中为 RestApi 和 Websocket 创建自定义域

    WebSocket 自定义域

    ApiGWCustomDomainName:
        Type: 'AWS::ApiGateway::DomainName'
        Properties:
          RegionalCertificateArn: !Ref RegionalCertificateArn
          DomainName: !Ref DomainName
          EndpointConfiguration:
            Types:
              - REGIONAL
          SecurityPolicy: TLS_1_2
      
      AppApiMapping:
        Type: 'AWS::ApiGatewayV2::ApiMapping'
        Properties:
          ApiMappingKey : !Ref BasePath
          DomainName: !Ref ApiGWCustomDomainName
          ApiId: !Ref  websocketAPI
          Stage : !Ref Stage
    

    休息 API

    ApiGWCustomDomainName:
        Type: 'AWS::ApiGateway::DomainName'
        Properties:
          CertificateArn: !Ref CertificateArn
          DomainName: !Ref DomainName
      
      AppApiMapping:
        Type: 'AWS::ApiGateway::BasePathMapping'
        Properties:
          BasePath: !Ref BasePath
          DomainName: !Ref ApiGWCustomDomainName
          RestApiId: !Ref RestApi
          Stage : !Ref ApiStageName
    

    【讨论】:

      猜你喜欢
      • 2021-06-08
      • 2015-10-11
      • 2021-05-23
      • 2020-10-04
      • 2018-05-29
      • 2019-07-30
      • 2021-02-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多