Skip to content

Commit

Permalink
Add filter for cognito identity fields (#6005)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfangl committed May 5, 2022
1 parent f7b06de commit 33bb976
Show file tree
Hide file tree
Showing 11 changed files with 1,098 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Expand Up @@ -116,7 +116,7 @@ jobs:
LAMBDA_EXECUTOR: "docker"
USE_SSL: 1
TEST_ERROR_INJECTION: 1
TEST_PATH: "tests/integration/awslambda/ tests/integration/test_integration.py"
TEST_PATH: "tests/integration/awslambda/ tests/integration/test_integration.py tests/integration/test_apigateway.py"
PYTEST_ARGS: "--reruns 2 --junitxml=target/reports/lambda-docker.xml -o junit_suite_name='lambda-docker'"
COVERAGE_ARGS: "-p"
command: make test-coverage
Expand All @@ -125,7 +125,7 @@ jobs:
environment:
DEBUG: 1
LAMBDA_EXECUTOR: "docker-reuse"
TEST_PATH: "tests/integration/awslambda/ tests/integration/test_integration.py"
TEST_PATH: "tests/integration/awslambda/ tests/integration/test_integration.py tests/integration/test_apigateway.py"
PYTEST_ARGS: "--reruns 2 --junitxml=target/reports/lambda-docker-reuse.xml -o junit_suite_name='lambda-docker-reuse'"
COVERAGE_ARGS: "-p"
command: make test-coverage
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/pro-integration.yml
Expand Up @@ -116,7 +116,8 @@ jobs:
source .venv/bin/activate
python -m pytest --reruns 2 --durations=10 --show-capture=no --junitxml=target/reports/lambda-docker.xml -o junit_suite_name='lambda-docker' \
../localstack/tests/integration/awslambda/ \
../localstack/tests/integration/test_integration.py
../localstack/tests/integration/test_integration.py \
../localstack/tests/integration/test_apigateway.py
- name: Run Lambda Tests for lambda executor docker-reuse
env:
DEBUG: 0
Expand All @@ -128,7 +129,8 @@ jobs:
source .venv/bin/activate
python -m pytest --reruns 2 --durations=10 --show-capture=no --junitxml=target/reports/lambda-docker-reuse.xml -o junit_suite_name='lambda-docker-reuse' \
../localstack/tests/integration/awslambda/ \
../localstack/tests/integration/test_integration.py
../localstack/tests/integration/test_integration.py \
../localstack/tests/integration/test_apigateway.py
- name: Publish LocalStack Community Integration Test Results
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
Expand Down
12 changes: 9 additions & 3 deletions localstack/services/awslambda/lambda_executors.py
Expand Up @@ -41,6 +41,7 @@
sqs_error_to_dead_letter_queue,
)
from localstack.utils.cloudwatch.cloudwatch_util import cloudwatched
from localstack.utils.collections import select_attributes
from localstack.utils.common import (
TMP_FILES,
CaptureOutput,
Expand Down Expand Up @@ -108,6 +109,9 @@
# CWD folder of handler code in Lambda containers
DOCKER_TASK_FOLDER = "/var/task"

# TODO remove once clarification of apigateway contexts is complete. Really bad hack!!
ALLOWED_IDENTITY_FIELDS = ["cognitoIdentityId", "cognitoIdentityPoolId"]

# Lambda event type
LambdaEvent = Union[Dict[str, Any], str, bytes]

Expand Down Expand Up @@ -141,11 +145,13 @@ def __init__(
self.invoked_function_arn = lambda_function.arn()
if qualifier:
self.invoked_function_arn += ":" + qualifier
self.cognito_identity = context.get("identity")
self.cognito_identity = context.get("identity") and select_attributes(
context.get("identity"), ALLOWED_IDENTITY_FIELDS
)
self.aws_request_id = str(uuid.uuid4())
self.memory_limit_in_mb = lambda_function.memory_size or self.DEFAULT_MEMORY_LIMIT
self.log_group_name = "/aws/lambda/%s" % self.function_name
self.log_stream_name = "%s/[1]%s" % (timestamp(format="%Y/%m/%d"), short_uid())
self.log_group_name = f"/aws/lambda/{self.function_name}"
self.log_stream_name = f"{timestamp(format='%Y/%m/%d')}/[1]{short_uid()}"

def get_remaining_time_in_millis(self):
# TODO implement!
Expand Down
@@ -0,0 +1 @@
target/

0 comments on commit 33bb976

Please sign in to comment.