Skip to content

Commit e5f25d3

Browse files
committed
add support for servicediscovery endpoints in API GW invocations
1 parent 2723825 commit e5f25d3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

localstack/services/apigateway/apigateway_listener.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,22 @@ def invoke_rest_api_integration(api_id, stage, integration, method, path, invoca
465465
return make_error_response(msg, 404)
466466

467467
elif integration_type in ['HTTP_PROXY', 'HTTP']:
468-
function = getattr(requests, method.lower())
468+
469+
if ':servicediscovery:' in uri:
470+
# check if this is a servicediscovery integration URI
471+
client = aws_stack.connect_to_service('servicediscovery')
472+
service_id = uri.split('/')[-1]
473+
instances = client.list_instances(ServiceId=service_id)['Instances']
474+
instance = (instances or [None])[0]
475+
if instance and instance.get('Id'):
476+
uri = 'http://%s/%s' % (instance['Id'], invocation_path.lstrip('/'))
469477

470478
# apply custom request template
471479
data = apply_template(integration, 'request', data)
472-
473480
if isinstance(data, dict):
474481
data = json.dumps(data)
475482

483+
function = getattr(requests, method.lower())
476484
result = function(uri, data=data, headers=headers)
477485

478486
# apply custom response template

0 commit comments

Comments
 (0)