通过 CloudFront 将 AppSync 与 CDK 结合使用

K..*_*K.. 1 amazon-cloudfront aws-appsync aws-cdk

我想在 CloudFront 发行版后面部署 AppSync API。

CloudFront 发行版需要 HTTP 源,如何从一个 CDK 堆栈内的 API 对象获取此源?

K..*_*K.. 5

我找到了解决方案。必须使用内在函数从分布构造中获取正确的值。

const api = new appsync.GraphqlApi(...);

const origin = new origins.HttpOrigin(
  cdk.Fn.select(2, cdk.Fn.split("/", api.graphqlUrl))
);

const distribution = new cloudfront.Distribution(this, "DemoDistribution", {
  defaultBehavior: { origin },
});
Run Code Online (Sandbox Code Playgroud)