【问题标题】:How to specify custom domain and certificate for Azure Functions using Serverless?如何使用无服务器为 Azure Functions 指定自定义域和证书?
【发布时间】:2021-10-21 09:51:36
【问题描述】:

我们使用无服务器将 graphql 处理程序函数部署为 Azure 函数并通过 APIM 访问它。

我们需要使用自己的自定义域(通过 CNAME 指向 Azure APIM 域),可以通过 Azure 门户手动设置,并上传证书+指定证书密码。

但是,如果我们执行“sls deploy”,则自定义域设置将被删除,因此我们需要以某种方式保留它或通过 serverless.yml 指定它,但我找不到有关如何执行此操作的任何信息。

当前 serverless.yml 配置:

service: my-service-${env:STAGE, 'develop'}
configValidationMode: off

provider:
  name: azure
  runtime: nodejs12
  region: north-europe
  resourceGroup: My-Service-Group
  subscriptionId: MySubscriptionId
  stage: ${env:STAGE, 'develop'}
  apim: true


plugins:
  - serverless-azure-functions

functions:
  graphql:
    handler: lib/azure.handler
    events:
      - http: true
        methods:
          - GET
          - POST
        authLevel: anonymous # can also be `function` or `admin`
        route: graphql
      - http: true
        direction: out
        name: "$return"
        route: graphql

我们将不胜感激。

【问题讨论】:

    标签: azure azure-functions serverless azure-api-management


    【解决方案1】:

    为了设置证书,我们需要从 Azure 门户中选择 TSL/SSL 设置选项,然后我们可以创建应用服务托管证书。

    为此,我们需要按以下步骤添加自定义域:

    • 将域映射到应用程序
    • 我们需要购买通配符证书

    以下是我们通常的设置方式:

    最后,我们需要创建 DNS 规则。

    感谢codeproject,因为我们已经清楚地起草了所有信息

    从 apim 部分检查以下示例 serverless.yml:

    # serverless.yml
    
    apim:
      apis:
        - name: v1
          subscriptionRequired: false # if true must provide an api key
          displayName: v1
          description: V1 sample app APIs
          protocols:
            - https
          path: v1
          tags:
            - tag1
            - tag2
          authorization: none
      cors:
        allowCredentials: false
        allowedOrigins:
          - "*"
        allowedMethods:
          - GET
          - POST
          - PUT
          - DELETE
          - PATCH
        allowedHeaders:
          - "*"
        exposeHeaders:
          - "*"
     
    

    还有“sls 部署”

    检查无服务器 framework 和 azure deployment 文档

    【讨论】:

    • 谢谢,看看我们是否可以以这种方式使用已经存在的通配符证书。但到目前为止它看起来不错;)
    • 我什至不需要更改 serverless.yml 中的任何内容,将自定义域移动到应用程序服务而不是 api 管理服务中就足够了。非常感谢!
    • @StefanHSinger 很高兴,它帮助了你
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-26
    • 2018-11-27
    • 2018-03-06
    • 2019-08-30
    • 2010-12-11
    • 2021-07-14
    • 1970-01-01
    相关资源
    最近更新 更多