Skip to content
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
19 changes: 19 additions & 0 deletions github-action-test/lambda/suite0.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@
}
}
]
},
{
"name": "test_client_context_custom_is_delivered",
"handler": "core.echoClientContextCustom",
"request": {},
"clientContext": {
"custom": {
"value": "hello"
}
},
"assertions": [
{
"response": {
"custom": {
"value": "hello"
}
}
}
]
}
]
}
4 changes: 4 additions & 0 deletions github-action-test/lambda/tasks/nodejs/core.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ export const ping = async (event) => {
msg: `pong[${event.msg}]`
};
};

export const echoClientContextCustom = async (_event, context) => {
return { custom: context.clientContext?.custom ?? null };
};
6 changes: 5 additions & 1 deletion github-action-test/lambda/tasks/python/core.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
def ping(event, context):
return {"msg": "pong[" + event['msg'] + "]"}
return {"msg": "pong[" + event['msg'] + "]"}

def echoClientContextCustom(event, context):
custom = context.client_context.custom if context.client_context else None
return {"custom": custom}
13 changes: 9 additions & 4 deletions src/containerized_test_runner/docker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import base64
import json
import re
import subprocess
Expand All @@ -24,8 +25,8 @@
_request_timeout_secs = float(os.environ.get("REQUEST_TIMEOUT_SECS", "30"))
REQUEST_TIMEOUT = (5, _request_timeout_secs)

# Lambda Runtime Interface header names
HEADER_CLIENT_CONTEXT = "Lambda-Runtime-Client-Context"
# Lambda Runtime Interface header names.
HEADER_CLIENT_CONTEXT = "X-Amz-Client-Context"
HEADER_COGNITO_IDENTITY_ID = "Lambda-Runtime-Cognito-Identity-Id"
HEADER_COGNITO_IDENTITY_POOL_ID = "Lambda-Runtime-Cognito-Identity-Pool-Id"
HEADER_XRAY_TRACE = "Lambda-Runtime-XRay-Trace-Header"
Expand Down Expand Up @@ -188,7 +189,9 @@ def _execute_single_request(self, request: Request, local_address: str) -> Union
headers.update(request.headers)

if request.client_context:
headers[HEADER_CLIENT_CONTEXT] = json.dumps(request.client_context)
headers[HEADER_CLIENT_CONTEXT] = base64.b64encode(
json.dumps(request.client_context).encode("utf-8")
).decode("ascii")
if request.cognito_identity:
if 'cognitoIdentityId' in request.cognito_identity:
headers[HEADER_COGNITO_IDENTITY_ID] = request.cognito_identity['cognitoIdentityId']
Expand Down Expand Up @@ -311,7 +314,9 @@ def _capture(self,
headers = {}
headers["Content-Type"] = request.content_type
if client_context:
headers[HEADER_CLIENT_CONTEXT] = json.dumps(client_context)
headers[HEADER_CLIENT_CONTEXT] = base64.b64encode(
json.dumps(client_context).encode("utf-8")
).decode("ascii")
if 'cognitoIdentityId' in cognito_identity:
headers[HEADER_COGNITO_IDENTITY_ID] = cognito_identity['cognitoIdentityId']
if 'cognitoIdentityPoolId' in cognito_identity:
Expand Down
Loading