{"id":1587,"date":"2020-11-27T15:49:15","date_gmt":"2020-11-27T07:49:15","guid":{"rendered":"https:\/\/9incloud.com\/?p=1587"},"modified":"2020-11-28T16:36:08","modified_gmt":"2020-11-28T08:36:08","slug":"api-gateway-custom-domain-cloudformation-debug","status":"publish","type":"post","link":"https:\/\/9incloud.com\/aws\/cloudformation\/api-gateway-custom-domain-cloudformation-debug","title":{"rendered":"API Gateway Custom Domain CloudFormation \u9664\u932f"},"content":{"rendered":"\n
\u5728\u73fe\u6709 API Gateway \u4e2d\u52a0\u5165\u81ea\u8a02\u7db2\u57df\u6642\uff0c\u9700\u8981\u6ce8\u610f Endpoint type\uff0c\u6709\u5206 Regional<\/em> \u3001edge-optimized<\/em>\u3001private<\/em> \u4e09\u7a2e\uff0c\u4ee5 public endpoint \u4f86\u8aaa\uff0c\u6709 Regional<\/em> \u3001edge-optimized<\/em> \u5169\u7a2e\uff0c\u5728\u52a0\u5165\u81ea\u8a02\u7db2\u57df\u6642\uff0c\u5fc5\u5b9a\u9700\u8981 SSL \u6191\u8b49 (AWS \u7a31\u70ba ACM)\uff0c\u5728\u65b0\u589e ACM \u9700\u8981\u6ce8\u610f Region \u7684\u554f\u984c<\/p>\n\n\n\n \u5047\u8a2d\u5982\u679c API Gateway \u7684 Endpoint type \u662f Regional\uff0c CloudFormation \u7684\u8a2d\u5b9a\u5982\u4e0b<\/p>\n<\/div>\n\n\n\n \u00a0<\/p>\n Invalid request provided: Invalid certificate ARN: arn:aws:acm:ap-northeast-1:093611479171:certificate\/edd8180c-8575-45ca-8947-e2d432c521e4. Certificate must be in ‘us-east-1’. (Service: ApiGateway, Status Code: 400, Request ID: 15bee123-53f5-4f6a-b44e-940505c825d0, Extended Request ID: null)<\/p>\n \u00a0<\/p>\n \u9019\u500b\u932f\u8aa4\u6700\u4e3b\u8981\u662f\u4ee5\u4e0b\u7684\u8a2d\u5b9a<\/p>\n \u6b64\u8a2d\u5b9a\u662f\u91dd\u5c0d edge-optimized endpoint type\uff0c\u800c\u6b64 type \u53ea\u80fd\u4f7f\u7528us-east-1<\/strong><\/em> \u7684 ACM\uff0c\u56e0\u70ba\u662f\u91dd\u5c0d worldwide\uff0c\u6240\u4ee5\u6191\u8b49\u4e0a\u7684 regional \u8981\u7279\u5225\u6ce8\u610f<\/p>\n \u53e6\u5916 CustomDomainRecord.Properties.AliasTarget.DNSName \u548c HostedZoneId \u7684\u8a2d\u5b9a\u4e5f\u8981\u6ce8\u610f\uff0cDistributionDomainName \u548c DistributionHostedZoneId \u4e5f\u662f\u91dd\u5c0d edge-optimized endpoint type<\/p>\n \u6700\u5f8c\uff0c\u5982\u679c\u662f\u91dd\u5c0d Regional endpoint type\uff0c\u6b63\u78ba\u7684 CloudFormation \u7684\u6b63\u78ba\u8a2d\u5b9a\u5982\u4e0b<\/p>\n<\/div>\n\n\n\n \u00a0<\/p>\n API Gateway \u4e2d\u7684 Stage \u8a2d\u5b9a\u82e5\u70ba \u5047\u8a2d\u50b3\u5165\u7684\u5b8c\u6574\u7684 url \u662f\u9019\u6a23<\/p>\n Lambda \u90a3\u908a\u63a5\u5230\u7684 path \u53ea\u6709 \/oauth\/token<\/strong><\/em> \uff0c\u76f8\u5c0d\u7684\uff0c\u5982\u679c custom domain \u662f\u9019\u6a23<\/p>\n \u90a3\u9ebc\u5728\u6e2c\u8a66\u6642\uff0c\u6703\u6c38\u9060\u5f97\u5230 404<\/strong><\/em> \uff0c\u56e0\u70ba\u50b3\u5165 Lambda \u6642\uff0cpath \u6703\u8b8a\u6210 \/dev\/oauth\/token<\/strong><\/em> \uff0c\u60f3\u7576\u7136\u723e\uff0croute \u7684\u5224\u65b7\u5c31\u6703\u932f\u8aa4<\/p>\n \u6240\u4ee5\u5728 CloudFormation \u4e2d\u7684 BasePathMapping.Properties.BasePath \u4e0d\u8981\u8a2d\u5b9a\uff0c\u5c31\u4e0d\u6703\u6709\u9019\u500b\u554f\u984c<\/p>\n<\/div>\n\n\n\n <\/p>\n","protected":false},"excerpt":{"rendered":" \u5728\u73fe\u6709 API Gateway \u4e2d\u52a0\u5165\u81ea<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[65,70],"tags":[],"yoast_head":"\nAWSTemplateFormatVersion: \"2010-09-09\"\nDescription: \"Setup API Gateway custom domain name\"\nParameters:\n AcmArn:\n Type: String\n CustomDomainName:\n Type: String\n ApiID:\n Type: String\n DomainHostZoneId:\n Type: String\nResources:\n ApiGatewayCustomDomainName:\n Type: \"AWS::ApiGateway::DomainName\"\n Properties:\n CertificateArn: !Ref AcmArn\n DomainName: !Ref CustomDomainName\n BasePathMapping:\n Type: \"AWS::ApiGateway::BasePathMapping\"\n DependsOn: ApiGatewayCustomDomainName\n Properties:\n DomainName: !Ref CustomDomainName\n RestApiId: !Ref ApiID\n Stage: dev\n CustomDomainRecord:\n Type: \"AWS::Route53::RecordSet\"\n DependsOn: ApiGatewayCustomDomainName\n Properties:\n Name: !Ref CustomDomainName\n Type: A\n HostedZoneId: !Ref DomainHostZoneId\n AliasTarget:\n DNSName: !GetAtt ApiGatewayCustomDomainName.DistributionDomainName\n HostedZoneId: !GetAtt ApiGatewayCustomDomainName.DistributionHostedZoneId\n<\/code><\/pre>\n\n\n\n
CloudFormation \u932f\u8aa4\u8a0a\u606f<\/h4>\n
\n
\nApiGatewayCustomDomainName.Properties.CertificateArn\n<\/code><\/pre>\n
AWSTemplateFormatVersion: \"2010-09-09\"\nDescription: \"Setup API Gateway custom domain name\"\nParameters:\n AcmArn:\n Type: String\n CustomDomainName:\n Type: String\n ApiID:\n Type: String\n DomainHostZoneId:\n Type: String\nResources:\n ApiGatewayCustomDomainName:\n Type: \"AWS::ApiGateway::DomainName\"\n Properties:\n EndpointConfiguration:\n Types:\n - REGIONAL\n RegionalCertificateArn: !Ref AcmArn\n DomainName: !Ref CustomDomainName\n BasePathMapping:\n Type: \"AWS::ApiGateway::BasePathMapping\"\n DependsOn: ApiGatewayCustomDomainName\n Properties:\n DomainName: !Ref CustomDomainName\n RestApiId: !Ref ApiID\n Stage: dev\n CustomDomainRecord:\n Type: \"AWS::Route53::RecordSet\"\n DependsOn: ApiGatewayCustomDomainName\n Properties:\n Name: !Ref CustomDomainName\n Type: A\n HostedZoneId: !Ref DomainHostZoneId\n AliasTarget:\n DNSName: !GetAtt ApiGatewayCustomDomainName.RegionalDomainName\n HostedZoneId: !GetAtt ApiGatewayCustomDomainName.RegionalHostedZoneId\n<\/code><\/pre>\n\n\n\n
Custom Domain \u53e6\u5916\u8981\u6ce8\u610f\u7684\u5730\u65b9<\/h4>\n
dev<\/code>\uff0c\u5247\u6574\u500b Invoke URL \u5927\u6982\u9577\u7684\u50cf\u9019\u6a23\uff0curl \u6703\u81ea\u52d5\u52a0\u5165 \/dev \u7576\u6210\u5f8c\u7db4<\/p>\n
https:\/\/xxxxxx.execute-api.ap-northeast-1.amazonaws.com\/dev\n<\/code><\/pre>\n
https:\/\/xxxxxx.execute-api.ap-northeast-1.amazonaws.com\/dev\/oauth\/token\n<\/code><\/pre>\n
https:\/\/example.com\/dev\/oauth\/token\n<\/code><\/pre>\n