如何使用 CloudFormation 在自定义源上设置源路径?

How to set the origin path on an Custom origin using CloudFormation?

我试过了

{
   "DomainName": "myapi.execute-api.us-east-1.amazonaws.com/dev,
   "Id": "APIEndPoint",
   "CustomOriginConfig": {
   "OriginProtocolPolicy": "https-only",
   "OriginSSLProtocols":["TLSv1", "TLSv1.1", "TLSv1.2"]
}

参考:https://aws.amazon.com/about-aws/whats-new/2014/12/16/amazon-cloudfront-now-allows-directory-path-as-origin-name/.

但我收到以下错误

The parameter origin name must be a domain name.
(Service: AmazonCloudFront; 
Status Code: 400; 
Error Code: InvalidArgument; Request ID:

我找到了答案,我们只需要添加 OriginPath 属性。在这里

{
  "DomainName": {
    "Ref": "APIGatewayEndpoint"
  },
  "Id": "APIEndPoint",
  "CustomOriginConfig": {
    "OriginProtocolPolicy": "https-only",
    "OriginSSLProtocols": [
      "TLSv1",
      "TLSv1.1",
      "TLSv1.2"
    ]
  },
  "OriginPath": {
    "Fn::Join": [
      "",
      [
        "/",
        {
          "Ref": "APIStage"
        }
      ]
    ]
  }
}