How to update <HTTPTargetConnection> in Apigee Edge Proxy Dynamically or Runtime?

I am deploying some service called MyService on Ec2 and got the ip or url let's say https://myservice.com

Now I want to use this url https://myservice.com in apigee edge runtime,

Let's say, Below is Apigee Edge Proxy Project Structure.

apiproxy
  - policies
    - somepolicy
  - proxies
    - default.xml
  - targets
    - default.xml
  apiproxy.xml

In below xml file from targets/default.xml, I want to replace https://example.com url Dynamically or Runtime with the url (https://myservice.com) which I got when I deployed the Service called MyService on ec2.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<TargetEndpoint name="default">
  <PreFlow name="PreFlow">
    <Request/>
    <Response/>
  </PreFlow>
  <Flows/>
  <PostFlow name="PostFlow">
    <Request/>
    <Response/>
  </PostFlow>
  <HTTPTargetConnection>
    <URL>https://example.com</URL>
  </HTTPTargetConnection>
</TargetEndpoint>

Main reason behind updating this url runtime is:

In my network, we are updating urls on daily basis of the services which are deployed on ec2, here for example, it is MyService on ec2

0 1 904
1 REPLY 1

There are two ways to do this. 

  • With a TargetServer.  This is an entity, managed outside of the API Proxy, that you can use as an "indirect reference" to a host name.  For example, you can specify your target as "Server1", and attach https://myservice.com to "Server1".   Then later you can change "Server1"  to point to "https://my-other-service.com
  • With dynamic assignment to the context variable "target.url".  This overrides the static configuration of the URL element in the HTTPTargetConnection.  You might load the value to insert into "target.url" from a KVM table.  That would allow you to simply update that KVM, to direct target calls to a different upstream system. 

You can search the community for hints on both of these things.