Skip to content

Commit

Permalink
fix Lambda docker command and imports (localstack#1563)
Browse files Browse the repository at this point in the history
  • Loading branch information
whummer authored Sep 15, 2019
1 parent 491f1c4 commit 0d6a1dc
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ docker-push-master:## Push Docker image to registry IF we are currently on the m
)

docker-run: ## Run Docker image locally
($(VENV_RUN); bin/localstack start --docker)
($(VENV_RUN); bin/localstack start)

docker-mount-run:
MOTO_DIR=$$(echo $$(pwd)/.venv/lib/python*/site-packages/moto | awk '{print $$NF}'); echo MOTO_DIR $$MOTO_DIR; \
Expand Down
7 changes: 2 additions & 5 deletions localstack/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,9 @@ def is_linux():
# Make sure to keep this in sync with the above!
# Note: do *not* include DATA_DIR in this list, as it is treated separately
CONFIG_ENV_VARS = ['SERVICES', 'HOSTNAME', 'HOSTNAME_EXTERNAL', 'LOCALSTACK_HOSTNAME', 'LAMBDA_FALLBACK_URL',
'LAMBDA_EXECUTOR', 'LAMBDA_REMOTE_DOCKER', 'LAMBDA_DOCKER_NETWORK', 'USE_SSL', 'LOCALSTACK_API_KEY',
'DEBUG',
'LAMBDA_EXECUTOR', 'LAMBDA_REMOTE_DOCKER', 'LAMBDA_DOCKER_NETWORK', 'USE_SSL', 'DEBUG',
'KINESIS_ERROR_PROBABILITY', 'DYNAMODB_ERROR_PROBABILITY', 'PORT_WEB_UI', 'START_WEB',
'DOCKER_BRIDGE_IP',
'DEFAULT_REGION',
'LAMBDA_JAVA_OPTS']
'DOCKER_BRIDGE_IP', 'DEFAULT_REGION', 'LAMBDA_JAVA_OPTS', 'LOCALSTACK_API_KEY']

for key, value in six.iteritems(DEFAULT_SERVICE_PORTS):
clean_key = key.upper().replace('-', '_')
Expand Down
7 changes: 3 additions & 4 deletions localstack/services/awslambda/lambda_executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def prepare_execution(self, func_arn, env_vars, runtime, command, handler, lambd

if config.LAMBDA_REMOTE_DOCKER:
cmd = (
'CONTAINER_ID="$(docker create -i'
'CONTAINER_ID="$(%s create -i'
' %s'
' %s'
' %s'
Expand All @@ -582,9 +582,8 @@ def prepare_execution(self, func_arn, env_vars, runtime, command, handler, lambd
')";'
'%s cp "%s/." "$CONTAINER_ID:/var/task"; '
'%s start -ai "$CONTAINER_ID";'
) % (entrypoint, debug_docker_java_port, env_vars_string, network_str, runtime, command,
docker_cmd,
lambda_cwd,
) % (docker_cmd, entrypoint, debug_docker_java_port, env_vars_string, network_str, runtime, command,
docker_cmd, lambda_cwd,
docker_cmd)
else:
lambda_cwd_on_host = self.get_host_path_for_path_in_docker(lambda_cwd)
Expand Down
5 changes: 5 additions & 0 deletions localstack/services/generic_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ def do_OPTIONS(self):
self.method = requests.options
self.forward('OPTIONS')

def do_CONNECT(self):
self.method = None
self.headers['Connection'] = self.headers.get('Connection') or 'keep-alive'
self.forward('CONNECT')

def read_content(self):
content_length = self.headers.get('Content-Length')
if content_length:
Expand Down
8 changes: 7 additions & 1 deletion localstack/utils/testutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import requests
import shutil
import zipfile
import importlib
from six import iteritems
from localstack.config import DEFAULT_REGION
from localstack.utils.aws import aws_stack
Expand All @@ -30,6 +31,11 @@ def create_lambda_archive(script, get_content=False, libs=[], runtime=None, file
# copy libs
for lib in libs:
paths = [lib, '%s.py' % lib]
try:
module = importlib.import_module(lib)
paths.append(module.__file__)
except Exception:
pass
target_dir = tmp_dir
root_folder = os.path.join(LOCALSTACK_VENV_FOLDER, 'lib/python*/site-packages')
if lib == 'localstack':
Expand All @@ -38,7 +44,7 @@ def create_lambda_archive(script, get_content=False, libs=[], runtime=None, file
target_dir = os.path.join(tmp_dir, lib)
mkdir(target_dir)
for path in paths:
file_to_copy = os.path.join(root_folder, path)
file_to_copy = path if path.startswith('/') else os.path.join(root_folder, path)
for file_path in glob.glob(file_to_copy):
name = os.path.join(target_dir, file_path.split(os.path.sep)[-1])
if os.path.isdir(file_path):
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ forbiddenfruit==0.1.3
jsonpath-rw==1.4.0
localstack-ext[full]>=0.10.2
localstack-ext>=0.10.2 #basic-lib
localstack-client>=0.10 #basic-lib
localstack-client>=0.12 #basic-lib
moto-ext>=1.3.14.1
nose>=1.3.7
nose-timer>=0.7.5
Expand All @@ -39,6 +39,6 @@ pyyaml>=3.13,<=5.1
requests>=2.20.0
requests-aws4auth==0.9
six>=1.12.0 #basic-lib
subprocess32-ext==3.2.8.2 #basic-lib
subprocess32==3.5.4 #basic-lib
xmltodict>=0.11.0
# yappi==1.0

0 comments on commit 0d6a1dc

Please sign in to comment.