如何使用CloudFormation创建AWS API Gateway自定义域?

时间:2019-09-04 04:36:24

标签: amazon-web-services amazon-cloudformation

我正在尝试为API网关创建自定义域,
我已经在ACM中导入了SSL。

我正在尝试运行以下模板,
但是我遇到了错误-

AWSTemplateFormatVersion: 2010-09-09
Transform: 'AWS::Serverless-2016-10-31'
Description: Test Custom Domain

Resources:
  Type: AWS::ApiGateway::DomainName
  Properties: 
    CertificateArn: !Sub 'arn:aws:acm:${AWS::Region}:${AWS::AccountId}:certificate/xxxx-xxx-xxx-xxxx-xxxx'
    DomainName: 'test-api.example.com'
    EndpointConfiguration: 
      Types: 
        - 'EDGE'

错误-

Transform AWS::Serverless-2016-10-31 failed with: Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. All 'Resources' must be Objects. If you're using YAML, this may be an indentation issue.. Rollback requested by user.

参考->
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html

2 个答案:

答案 0 :(得分:0)

错误告诉您问题所在。您正在使用YAML,但缩进不正确。

要解决您的问题,请修复Properties属性的缩进,使其比TypeProperties属性缩进一个标签。

答案 1 :(得分:0)

问题是缺少逻辑ID,
每个要创建的资源都必须属于逻辑编号-

AWSTemplateFormatVersion: 2010-09-09
Transform: 'AWS::Serverless-2016-10-31'
Description: Test Custom Domain

Resources:
  test:
    Type: AWS::ApiGateway::DomainName
    Properties: 
      CertificateArn: !Sub 'arn:aws:acm:${AWS::Region}:${AWS::AccountId}:certificate/xxxx-xxx-xxx-xxxx-xxxx'
      DomainName: 'test-api.example.com'
      EndpointConfiguration: 
        Types: 
          - 'EDGE'