通过 CloudFront 将 AppSync 与 CDK 结合使用

Using AppSync via CloudFront with the CDK

我想在 CloudFront 分发后部署 AppSync API。

CloudFront 分发需要一个 HTTP 源,我如何从一个 CDK 堆栈中的 API 对象中获取它?

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

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 },
});