首页 \ 问答 \ 如何使用API网关调用EC2上运行的其他服务(How to use API gateway to call another service running on an EC2)

如何使用API网关调用EC2上运行的其他服务(How to use API gateway to call another service running on an EC2)

我有一个令人困惑的场景。 我是AWS的新手。 我有一些用java jersy编写的可用服务,我将它们部署在Ec2实例上。

我被要求使用API​​网关来调用这些服务,而不是直接调用它们。 例如,如果我有如下服务:

http://domainname/article/2

我希望前端首先调用API网关的以下端点:

https://my-api-id.execute-api.region-id.amazonaws.com/stage-name/article

然后上面的API网关端点调用我的服务。 我在想的是当我尝试创建API网关资源时,在集成类型中有一个http代理。 我认为这可以适合我的目的,但我不确定它,我完全困惑。

任何人都可以阐明我如何实现这一目标吗?


I have a confusing scenario. I am new to AWS. I have some available services written in java jersy and I have them deployed on an Ec2 instance.

I am asked to use API gateway to call these services rather than calling them directly. So for instance if I have a service as follows:

http://domainname/article/2

I want the front end to first call the following endpoint of API gateway:

https://my-api-id.execute-api.region-id.amazonaws.com/stage-name/article

and then the above API Gateway end point call the my service. What I am thinking is there is a http proxy in integration type when I try to create the API gateway resource. I assume this can fit my purpose but I am not sure about it and I am totally confused.

Can anyone shed light on how I can achieve that?


原文:https://stackoverflow.com/questions/44033356
更新时间:2022-10-24 14:10

最满意答案

如果你发现自己不得不做这种事情,那么你不是在使用多态,可能需要检查你的设计。 但是你可以使用dynamic_cast和test:

B* b = dynamic_cast<B*>(someAPtr);
if (b)
{
  // cast succeeded, object pointed at is-a-B
}

这将是一个使用多态的设计:

struct A {
  virtual void foo() const {}
};

struct B : A {
  void foo() const override {}
};

struct C : A {
  void foo() const override {}
};

int f(A* arg) { 
  arg->foo();
  return 42; 
}

请注意, override说明符是C ++ 11。 如果您的编译器不支持它,您可以省略它。 它只是确保我不会错误地覆盖基类的虚方法。


If you find yourself having to do this kind of thing, then you are not using polymorphism and may need to review your design. But you can use dynamic_cast and test:

B* b = dynamic_cast<B*>(someAPtr);
if (b)
{
  // cast succeeded, object pointed at is-a-B
}

This would be a design using polymorphism:

struct A {
  virtual void foo() const {}
};

struct B : A {
  void foo() const override {}
};

struct C : A {
  void foo() const override {}
};

int f(A* arg) { 
  arg->foo();
  return 42; 
}

Note that the override specifier is C++11. If your compiler doesn't support it, you can omit it. It is just ensuring that I don't mistakenly fail to override a virtual method of a base class.

相关问答

更多
  • 所以,使用这个线程我已经解决了我的问题。 首先,我的Base类以这种方式导出到python: bp::class_("Base", bp::no_init) 我不得不删除bp::no_init 。 为什么? 看看下一次更新(在之前我给出的stackoverflow后的答案): class Der(Base): def __init__(self): super(Der, self).__init__() # Add this! ...
  • 您必须将模拟存储为MockFile,如下所示: std::unique_ptr mockFile(new MockFile); EXPECT_CALL(*mockFile, save(_)); my_method(mockFile); 但是您需要更改方法的签名。 引用unique_ptr是很奇怪的,因为拥有该对象的人并不干净。 如果my_method拥有mockFile,则通过将指针移入方法(通过值传递)来转移所有权。 如果my_method不拥有该文件,则将其作为普通指针传递。 Yo ...
  • 根据您分配给temp_message的内容,它可能只是Message而不是MessageA。 使用dynamic_cast而不是static_cast,然后检查temp是否为nullptr / NULL。 如果为NULL,则temp_message是Message而不是MessageA。 I found a quick and valid solution: ReceiveSingle(Message** message) { MessageA* new_message = new Message ...
  • 是的, 如果且仅当基类析构函数是虚拟的,那么这个工作将是基础类,而不是为IFoo基类。 如果基类析构函数是虚拟的,那么当在基类指针上调用operator delete时,它将使用动态调度来查找如何通过查找虚函数表中的派生类析构函数来删除该对象。 在多重继承的情况下,只有通过删除它的基类具有虚拟析构函数时,它才会工作; 其他基类没有虚拟析构函数可以,但只有当您不尝试通过其他基类指针删除任何派生对象时,才可以。 Yes, it will work, if and only if the base class d ...
  • 如果我告诉你我有一只狗,你可以放心地假设我有一只宠物。 如果我告诉你我有一只宠物,你不知道那只动物是一只狗,它可能是一只猫,甚至是长颈鹿。 不知道一些额外的信息,你不能放心地假设我有一只狗。 类似地,派生对象是基类对象(因为它是一个子类),因此可以由基类指针指向。 但是,基类对象不是派生类对象,因此不能将其分配给派生类指针。 (你现在听到的吱吱声是类比拉伸) 假设你现在想给我买一个礼物给我的宠物。 在第一种情况下,你知道这是一只狗,你可以买一条皮带,每个人都快乐。 在第二种情况下,我没有告诉你我的宠物是什么 ...
  • 是的,指针a保持不变直到我们从main函数返回 变量b(4字节指针)是自动的。 每次调用test函数时都会创建它。 一旦我们从它返回,变量就会消失(指针)。 请注意,b点的值不受影响。 在大多数情况下,我认为,在编译期间只会分配一个块(很可能在只读内存中),并且该函数将在每次调用时返回相同的指针。 如果SetTabToolTipText使用一些内存管理工具new / malloc或某些特定于操作系统的内部分配字符串,则应该进行额外的清理。 否则会有内存泄漏。 如果内部没有发生这种情况(文档或注释等中没有提到 ...
  • 如果你发现自己不得不做这种事情,那么你不是在使用多态,可能需要检查你的设计。 但是你可以使用dynamic_cast和test: B* b = dynamic_cast(someAPtr); if (b) { // cast succeeded, object pointed at is-a-B } 这将是一个使用多态的设计: struct A { virtual void foo() const {} }; struct B : A { void foo() const overr ...
  • 粗略地说,该成员属于子对象,因此您必须使用其类型来识别它。 确实非常好。 反过来甚至没有实际编译: struct Ptr : std::integral_constant {}; 错误很明显: 错误:无法将模板参数'&Base :: foo'从'[...](Base :: )()const}'转换为'[...](Der :: )()const' 我用[...]减少它的地方。 Roughly speaking, the m ...
  • 派生类的对象总是在其中的某处包含基类类型的对象。 这称为“基类子对象”。 如果p具有类型base* ,那么当p被设置为指向derived类型的对象时,它实际上被设置为指向该derived对象的base子对象。 此行为确保可以从指针调用基类非静态成员函数,即使它们实际指向派生类的对象也是如此。 因此,实现不必在运行时查找p指向完整的base对象还是完整的derived对象; 无论如何,它仍然指向一个base对象(可能只是一个基类子对象)。 为了确保即使您使用指向基类的指针调用派生类的函数实现,编译器也必须生成 ...
  • 示例代码: #include #include // Remember to add a virtual member function in A // to enable RTTI. struct A { virtual ~A() {} }; struct B : A { virtual ~B() {}}; int main() { A* ap = new B(); std::cout << typeid(ap).name() << std:: ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)