为AWS API Gateway Stage处理不同的端点 [英] Handling different end points for AWS API Gateway Stages

查看:139
本文介绍了为AWS API Gateway Stage处理不同的端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够更改在每个API网关方法中定义的终点,以便名为"Dev"的登台环境指向我的内部Dev API,并且Prod阶段当然会路由到我的Production API.

I want to be able to change my end point defined in each API Gateway method so that a staging environment called "Dev" points to my internal Dev API and Prod stage of course would route to my Production API.

现在,我必须手动更改每种方法,然后部署到产品标签,但是现在要进行任何测试,我必须在开发阶段再次将它们全部更改.

Right now I'd have to manually change each method and then deploy to the prod stag but now to do any testing I'd have to change them all back again for a dev stage.

我正在通过DNS转换将Dev迁移到Prod,但是将来的开发仍然需要对每种方法进行更改.

I am moving ahead with a DNS switch to move Dev to Prod but future development still requires a change on every method.

示例:

我有一个名为User的资源和一个映射到端点(HTTP代理)的GET方法->

I have a resource called User and a GET Method which maps to an end point (HTTP Proxy) -> http://dev.mytestapp.com/api/v1/user

然后,我部署到一个称为Dev的阶段-Dev阶段为我提供了一个URL来调用以请求此资源. https://xxxxobl.execute-api.us-east-1 .amazonaws.com/dev/user

I then deploy to a Stage called Dev - the Dev stage gives me a URL to call to request this resource, eg. https://xxxxobl.execute-api.us-east-1.amazonaws.com/dev/user

现在我进行测试,它可以按预期工作,因此我想将其移至生产阶段,即所谓的阶段.当我部署到产品时,我的调用URL现在为 https://xxxxobl.execute-api.us-east-1.amazonaws.com/prod/user

Now I test and it works as expected so I want to move this to a production stage, just called stage. When I deploy to prod, my calling url is now https://xxxxobl.execute-api.us-east-1.amazonaws.com/prod/user

,但是问题在于API仍将端点映射到 http://dev. mytestapp.com/api/v1/user ,而不是 http://prod之类的东西. mytestapp.com/api/v1/user

but the problem is that the API is still mapping the end point to http://dev.mytestapp.com/api/v1/user and not something like http://prod.mytestapp.com/api/v1/user

因此,我的阶段和网址已更改,但是实际调用的API很难编码为开发人员.

So my stage and url have changed but the actual API being called is hard coded to dev.

有什么想法吗? 谢谢

推荐答案

您可以利用此页面>向您展示如何为http代理设置阶段变量.您也可以将阶段变量用于lambda函数.

You can take advantage of stage variables to have end points route to different APIs. This page shows you how to set up a stage variable for a http proxy. You can use the stage variables for lambda functions as well.

这篇关于为AWS API Gateway Stage处理不同的端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆