feat: use AWS Lambda entry point if ImageConfig.EntryPoint is set (#7326)

This commit is contained in:
Michael Krasnyk 2024-02-16 03:07:25 +07:00 committed by GitHub
parent 8576195462
commit a9cec5e780
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 0 deletions

View File

@ -1001,6 +1001,10 @@ class LambdaFunction(CloudFormationModel, DockerModel):
"host.docker.internal": "host-gateway" "host.docker.internal": "host-gateway"
} }
# Change entry point if requested
if self.image_config.entry_point:
run_kwargs["entrypoint"] = self.image_config.entry_point
# The requested image can be found in one of a few repos: # The requested image can be found in one of a few repos:
# - User-provided repo # - User-provided repo
# - mlupin/docker-lambda (the repo with up-to-date AWSLambda images # - mlupin/docker-lambda (the repo with up-to-date AWSLambda images

View File

@ -377,3 +377,39 @@ def test_invoke_lambda_with_proxy():
expected_payload = {"id": vol.id, "state": vol.state, "size": vol.size} expected_payload = {"id": vol.id, "state": vol.state, "size": vol.size}
assert json.loads(payload) == expected_payload assert json.loads(payload) == expected_payload
@mock_aws
def test_invoke_lambda_with_entrypoint():
conn = boto3.client("lambda", _lambda_region)
function_name = str(uuid4())[0:6]
conn.create_function(
FunctionName=function_name,
Runtime=PYTHON_VERSION,
Role=get_role_name(),
Handler="lambda_function.lambda_handler",
Code={"ZipFile": get_test_zip_file1()},
ImageConfig={
"EntryPoint": [
"/var/rapid/init",
"--bootstrap",
"/var/runtime/bootstrap",
"--enable-msg-logs",
],
},
Description="test lambda function",
Timeout=3,
MemorySize=128,
Publish=True,
)
in_data = {"hello": "world"}
result = conn.invoke(
FunctionName=function_name,
InvocationType="RequestResponse",
Payload=json.dumps(in_data),
)
assert result["StatusCode"] == 200
payload = result["Payload"].read().decode("utf-8")
assert json.loads(payload) == in_data