Add support for custom stepfunctions lambda endpoint (#2296)
diff --git a/README.md b/README.md
index b0b40cd3df33e..bc535da7bd414 100644
--- a/README.md
+++ b/README.md
@@ -186,6 +186,8 @@ You can pass the following environment variables to LocalStack:
 * `KINESIS_LATENCY`: Integer value (default: `500`) or `0` (to disable), causing the Kinesis API to delay returning a response in order to mimick latency from a live AWS call.
 * `DYNAMODB_ERROR_PROBABILITY`: Decimal value between 0.0 (default) and 1.0 to randomly
   inject `ProvisionedThroughputExceededException` errors into DynamoDB API responses.
+* `STEPFUNCTIONS_LAMBDA_ENDPOINT`: URL to use as the lambda service endpoint in step functions.
+  By default this is the localstack lambda endpoint.
 * `LAMBDA_EXECUTOR`: Method to use for executing Lambda functions. Possible values are:
     - `local`: run Lambda functions in a temporary directory on the local machine
     - `docker`: run each function invocation in a separate Docker container
diff --git a/localstack/config.py b/localstack/config.py
index ee66e106719d7..0f9fd72a65ba6 100644
--- a/localstack/config.py
+++ b/localstack/config.py
@@ -119,6 +119,9 @@
 # Whether to skip downloading additional infrastructure components (e.g., custom Elasticsearch versions)
 SKIP_INFRA_DOWNLOADS = os.environ.get('SKIP_INFRA_DOWNLOADS', '').strip()
 
+# Stepfunctions lambda endpoint override
+STEPFUNCTIONS_LAMBDA_ENDPOINT = os.environ.get('STEPFUNCTIONS_LAMBDA_ENDPOINT', '').strip()
+
 
 def has_docker():
     try:
@@ -159,7 +162,7 @@ def is_linux():
                    'USE_SSL', 'DEBUG', 'KINESIS_ERROR_PROBABILITY', 'DYNAMODB_ERROR_PROBABILITY', 'PORT_WEB_UI',
                    'START_WEB', 'DOCKER_BRIDGE_IP', 'DEFAULT_REGION', 'LAMBDA_JAVA_OPTS', 'LOCALSTACK_API_KEY',
                    'LAMBDA_CONTAINER_REGISTRY', 'TEST_AWS_ACCOUNT_ID', 'DISABLE_EVENTS', 'EDGE_PORT',
-                   'EDGE_PORT_HTTP', 'SKIP_INFRA_DOWNLOADS']
+                   'EDGE_PORT_HTTP', 'SKIP_INFRA_DOWNLOADS', 'STEPFUNCTIONS_LAMBDA_ENDPOINT']
 
 for key, value in six.iteritems(DEFAULT_SERVICE_PORTS):
     clean_key = key.upper().replace('-', '_')
diff --git a/localstack/services/stepfunctions/stepfunctions_starter.py b/localstack/services/stepfunctions/stepfunctions_starter.py
index 3f7f158b88b13..1f46bb4908c75 100644
--- a/localstack/services/stepfunctions/stepfunctions_starter.py
+++ b/localstack/services/stepfunctions/stepfunctions_starter.py
@@ -12,7 +12,7 @@
 
 
 def get_command():
-    lambda_endpoint = aws_stack.get_local_service_url('lambda')
+    lambda_endpoint = config.STEPFUNCTIONS_LAMBDA_ENDPOINT or aws_stack.get_local_service_url('lambda')
     dynamodb_endpoint = aws_stack.get_local_service_url('dynamodb')
     sns_endpoint = aws_stack.get_local_service_url('sns')
     sqs_endpoint = aws_stack.get_local_service_url('sqs')

This allows setting the lambda endpoint used for executing step functions to be different
to the localstack lambda endpoint.

This is useful for integration with eg. SAM or just the lambci docker images.

--

Note: I can't see any existing tests for similar environment variable/config code. If there is somewhere appropriate I should be adding tests then please let me know and I'll update!

Resolves #2296 