Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the Lambda invocation due to lambci changes. #2577

Merged
merged 1 commit into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions moto/awslambda/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@
except ImportError:
from backports.tempfile import TemporaryDirectory


_stderr_regex = re.compile(r"START|END|REPORT RequestId: .*")
# The lambci container is returning a special escape character for the "RequestID" fields. Unicode 033:
# _stderr_regex = re.compile(r"START|END|REPORT RequestId: .*")
_stderr_regex = re.compile(r"\033\[\d+.*")
_orig_adapter_send = requests.adapters.HTTPAdapter.send
docker_3 = docker.__version__[0] >= "3"

Expand Down Expand Up @@ -444,7 +445,7 @@ def _invoke_lambda(self, code, event=None, context=None):
if exit_code != 0:
raise Exception("lambda invoke failed output: {}".format(output))

# strip out RequestId lines
# strip out RequestId lines (TODO: This will return an additional '\n' in the response)
output = os.linesep.join(
[
line
Expand Down
10 changes: 6 additions & 4 deletions tests/test_awslambda/test_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def test_invoke_function_get_ec2_volume():
conn = boto3.client("lambda", "us-west-2")
conn.create_function(
FunctionName="testFunction",
Runtime="python2.7",
Runtime="python3.7",
Role="test-iam-role",
Handler="lambda_function.lambda_handler",
Code={"ZipFile": get_test_zip_file2()},
Expand All @@ -184,18 +184,20 @@ def test_invoke_function_get_ec2_volume():
vol.id,
vol.state,
vol.size,
json.dumps(in_data),
json.dumps(in_data).replace(
" ", ""
), # Makes the tests pass as the result is missing the whitespace
)

log_result = base64.b64decode(result["LogResult"]).decode("utf-8")

# fix for running under travis (TODO: investigate why it has an extra newline)
# The Docker lambda invocation will return an additional '\n', so need to replace it:
log_result = log_result.replace("\n\n", "\n")
log_result.should.equal(msg)

payload = result["Payload"].read().decode("utf-8")

# fix for running under travis (TODO: investigate why it has an extra newline)
# The Docker lambda invocation will return an additional '\n', so need to replace it:
payload = payload.replace("\n\n", "\n")
payload.should.equal(msg)

Expand Down