指定的域名标识符无效

Invalid domain name identifier specified

尝试通过 CloudFormation 创建 AWS::ApiGateway::BasePathMapping 时,出现以下错误:

Invalid domain name identifier specified

以下是我的 CloudFormation 模板中应该创建 AWS::ApiGateway::BasePathMapping:

的部分
{
    "Parameters": {
        "ApiDomainName": {
            "Description": "The domain name for the API",
            "Type": "String"
        }
    },
    "Resources": {
        "ApiBasePathMapping": {
            "Type": "AWS::ApiGateway::BasePathMapping",
            "Properties": {
                "DomainName": {
                    "Ref": "ApiDomainName"   
                },
                "RestApiId": {
                    "Ref": "RepositoryApi"
                },
                "Stage": {
                    "Ref": "ApiProductionStage"
                }
            },
            "DependsOn": [
                "ApiProductionStage"
            ]
        }
    }
}

documentation 没有提到它需要对 DomainName 有任何特殊要求,但该资源的文档似乎缺少一些信息(例如,它没有列出输出即使创建了 Distribution Domain Name 作为示例)。

堆栈的其余部分按预期工作。我正在尝试将此资源添加为变更集。我确实拥有我尝试使用的域,并且我已经在 ACM 中为该域创建了一个证书。

引用自 AWS 论坛:

You can only create or modify base path mappings after the domain name has been added to API Gateway. This "Invalid domain name identifier specified" error message is returned when the domain name given in the base path mapping is not found, indicating that it has not been added yet.

此外,截至 2017 年 3 月,通过 CloudFormation 将域名添加到 API 网关的唯一方法是通过 CloudFormation 提供的自定义资源。

参考:https://forums.aws.amazon.com/message.jspa?messageID=769627

现在可以做到这一点。您只需在您的 CFN 模板上明确声明存在依赖项 (DependsOn):

...
ApiDevMapping:
  Type: 'AWS::ApiGateway::BasePathMapping'
  Properties:
    BasePath: v1.0
    Stage: dev
    DomainName: my-api.example.com
    RestApiId: !Ref MobileApiDev
DependsOn:
  - MobileApiDevDomain
...