如何将 json 文件从 s3 返回到特定 url,但仅返回该 url

Zac*_*ach 4 amazon-s3 amazon-web-services amazon-cloudfront reactjs react-router

我有一个在其他地方设置的特殊 URL,无法更改。

mydomain.com/discountCards

我需要从我的 s3 存储桶返回一个 JSON,每当服务器向 mydomain.com/discountCards

问题是:

我在 mydomain.com 上使用 React-Router 的 React 应用程序。因此,转到 mydomain.com/discountCards 会显示一个白色的反应页面(因为该网址上没有任何内容)

我正在尝试将 Cloudfront 设置为直接链接到有效的 s3 JSON 文件 - 但问题是:

它仅适用于 mydomain.com/discountCards.json 不适用于 mydomain.com/discountCards

所以....现在我的 s3 存储桶有一个名为 discountCards.json 的文件 - 但我需要它是没有“.json”的折扣卡。

或者是其他东西?

如何使用 AWS s3、cloudfront 和 route 53 从我的 s3 返回此 .json 作为特定域?

就像我说的那样,我通过指向我的 s3 文件的 cloudfront 进行了所有设置,但它要求我在 URL 中包含文件扩展名(我不能这样做,该 URL 已经在 mydomain.com/discountCards 上锁定,而不是 discountCards .json)

这样其他网站和应用程序就可以获取该 URL 并返回一个 json。任何其他方式来实现这一目标?

kik*_*yu1 6

所以......现在我的 s3 存储桶有一个名为 discountCards.json 的文件 - 但我需要它是没有“.json”的折扣卡

将您的文件 discountCard.json 保存为不带 .json 扩展名的 discountCard。见下图

在此处输入图片说明

然后在元数据下的属性上添加content-typeapplication/json查看下图

在此处输入图片说明

现在可以通过这个网址访问存储桶https://s3.amazonaws.com/stackkkover/discountCards

这个答案的灵感来自这篇文章/sf/answers/1893225841/

我希望这个答案会有所帮助。谢谢你。