使用无服务器的WebSockets API的自定义域名 [英] Custom Domain Name for WebSockets API with Serverless

查看:25
本文介绍了使用无服务器的WebSockets API的自定义域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在管理一个使用无服务器的应用程序的睡觉API,我想在同一地区使用WebSockets API扩展此设置。所有内容都应使用相同的证书处理,但子域不同。

首先,我使用sls create_domain --stage=...创建了一个新的自定义域。 然后,我尝试将其添加到新的WebSockets堆栈中,但以以下错误结束:

错误:找不到.的CloudForms资源.

我在Github上发现,CloudFortification目前似乎不支持此功能,因此Serverless不支持此功能。

所以我尝试在UI中手动将舞台附加到自定义域名:

睡觉接口和HTTPAPI在同一域名下只能混用 通过API Gateway的V2 DomainName接口完成。目前, WebSocket API只能附加到具有其他接口的域名 WebSocket API。这也必须通过API Gateway的V2实现 DomainName接口。

出现更多念力,因为在本例中它甚至不是同一个域名。新域名为sockets.<DOMAIN>.com,现有域名为api.<DOMAIN>.com。还是不同的子域属于"相同的域名"?

尽管如此,我还是尝试通过apigatewayv2 CLI重新创建自定义域:

aws apigatewayv2 create-domain-name --domain-name <DOMAIN> --domain-name-configurations file://domain-configuration.json --region eu-west-1

domain-configuration ation.json:

[
{
    "ApiGatewayDomainName": "<DOMAIN>",
    "CertificateArn": "arn:aws:acm:us-east-1:<ACCOUNT_ID>:certificate/<CERT_ID>",
    "CertificateName": "<DOMAIN>",
    "DomainNameStatus": "AVAILABLE",
    "EndpointType": "EDGE",
    "SecurityPolicy": "TLS_1_2"
}

]

但这会导致以下错误:

调用CreateDomainName操作时出错(BadRequestException):无效证书arn:arn:aws:acm:us-east-1:924441585974:certificate/b88f0a3f-1393-4a16-a876-9830852b5207.证书必须为"eu-west-1"。

我的当前状态是API Gateway只允许自定义证书位于US-EAST-1,因此此错误让我更加困惑。

摘要:我完全不知道如何将自定义域名附加到我的WebSocket API工作台。我对每一个正确方向的提示都很高兴!

推荐答案

找到具有自定义云表单资源模板的解决方案:

resources:
  Resources:
    WebSocketDomainName:
      Type: AWS::ApiGatewayV2::DomainName
      Properties:
        DomainName: <domain-name>
        DomainNameConfigurations:
          - EndpointType: 'REGIONAL'
            CertificateArn: <cert-arn>
    WebSocketMapping:
      Type: AWS::ApiGatewayV2::ApiMapping
      Properties:
        ApiId: <api-id>
        DomainName: !Ref WebSocketDomainName
        Stage: <stage-name>
    DNSRecord:
      Type: AWS::Route53::RecordSet
      Properties:
        HostedZoneName: <hosted-zone-name>.
        TTL: '900'
        ResourceRecords:
          - !GetAtt [ WebSocketDomainName, RegionalDomainName ]
        Name: <domain-name>
        Type: CNAME

编辑:现在使用serverless-domain-manager!🎉

custom:
  customDomain:
    rest:
      domainName: rest.serverless.foo.com
      stage: ci
      basePath: api
      certificateName: '*.foo.com'
      createRoute53Record: true
      endpointType: 'regional'
      securityPolicy: tls_1_2
    http:
      domainName: http.serverless.foo.com
      stage: ci
      basePath: api
      certificateName: '*.foo.com'
      createRoute53Record: true
      endpointType: 'regional'
      securityPolicy: tls_1_2
    websocket:
      domainName: ws.serverless.foo.com
      stage: ci
      basePath: api
      certificateName: '*.foo.com'
      createRoute53Record: true
      endpointType: 'regional'
      securityPolicy: tls_1_2

这篇关于使用无服务器的WebSockets API的自定义域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆