簡體   English   中英

將aws WebSocket api連接到自定義域名

[英]Connect aws WebSocket api to custom domain name

我使用 aws WebSocket api 創建了一個消息傳遞應用程序,並使用無服務器進行部署。 API 已成功部署,我可以使用 wscat 測試這些 API。 我在堆棧中也有其他 Rest api。 I tried mapping my new WebSocket api stack to an existing domain name, but getting the error: 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. 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.

我被困住並試圖弄清楚要進行哪些更改。

I went through https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigatewayv2-api.html and https://docs.aws.amazon.com/apigateway/latest/developerguide/how -to-custom-domains.html但無法弄清楚。

在此處輸入圖像描述

在此處輸入圖像描述

API 配置

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

Rest 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM