AWS 无服务器 403 禁止 API 网关

AWS Serverless 403 forbidden API gateway

我正在尝试创建无服务器 Nodejs 应用程序。我将我的应用程序部署到 S3,它是 运行。但是 URL 似乎是 https://xxxxxxxx.xxxxx-api.us-west-2.amazonaws.com/prod. So, whenever my app is trying to get css files or video files or even the links they are going to URL/ which is perfect. But here the url is URL/prod, it should be like URL/prod/whichever-route-it-is 所以,我的静态文件没有被渲染,甚至链接也不起作用。有什么方法可以重新路由到 URL/prod 或从 api 端点删除产品?

将保存静态文件的文件夹移动到 S3 中的 /prod/ 子文件夹中。

或者,使用 Cloudfront 将 /css/、/js/ 或任何静态路径路由到 S3 存储桶并跳过 API 网关

或者,配置 API 网关以覆盖 /css/、/js/ 或其他路径

我更喜欢将文件移动到子文件夹或 Cloudfront 解决方案。这允许控制 API 的不同阶段。例如,当您准备好启动 v2,但还没有完全取消 v1 时,您可能希望 prod/ 和 prod_v2/ 可用。这样,您的文件夹结构就可以很好地映射到 API 网关阶段。

AWS API 网关在 URL 中遵循此模式:

www.example.com/my-base-path/MyStage

您必须相应地配置每个部分。例如,您可以为以下内容创建基本路径 "prod" 和阶段 "whichever-route-it-is":

www.example.com/prod/whichever-route-it-is

基本路径映射在自定义域名下配置。