我正在尝试使用 AWS CDK 设置具有 2 个不同来源的 CloudFront 分配:
我遇到的问题是我无法将 API 网关的域正确传递到 CloudFront 分配。这是我的尝试:
const api = new ag.RestApi(this, "RestApi", {
deploy: true
});
api.root
.addResource("api")
.addResource("photo")
.addResource("{id}")
.addMethod("GET", new ag.LambdaIntegration(lambdaFunction));
const url = URL.parse(api.url);
const domainName = url.hostname as string;
const dist = new cf.CloudFrontWebDistribution(this, "Distribution", {
originConfigs: [
{
s3OriginSource: { s3BucketSource: bucket },
behaviors: [{ isDefaultBehavior: true }]
},
{
customOriginSource: { domainName },
behaviors: [
{
pathPattern: "/api/*"
}
]
}
]
});
new …Run Code Online (Sandbox Code Playgroud)