Techdebt: Streamline AWSLambda/Docker tests (#6735)
This commit is contained in:
parent
58ee2cd61c
commit
8aafbdb58f
7
.github/workflows/tests_decoratormode.yml
vendored
7
.github/workflows/tests_decoratormode.yml
vendored
@ -34,6 +34,13 @@ jobs:
|
||||
pip install -r requirements-dev.txt
|
||||
pip install pytest-cov
|
||||
pip install pytest-github-actions-annotate-failures
|
||||
- name: Download Docker dependencies
|
||||
# This happens automatically during test execution
|
||||
# However, our tests can run concurrently
|
||||
# Which means that our tests can pull this image concurrently
|
||||
# Pulling it once is more efficient
|
||||
run: |
|
||||
docker pull mlupin/docker-lambda:python3.11
|
||||
- name: Test with pytest
|
||||
run: |
|
||||
make test-only
|
||||
|
7
.github/workflows/tests_servermode.yml
vendored
7
.github/workflows/tests_servermode.yml
vendored
@ -38,6 +38,13 @@ jobs:
|
||||
- name: Install project dependencies
|
||||
run: |
|
||||
pip install -r requirements-dev.txt
|
||||
- name: Download Docker dependencies
|
||||
# This happens automatically during test execution
|
||||
# However, our tests can run concurrently
|
||||
# Which means that our tests can pull this image concurrently
|
||||
# Pulling it once is more efficient
|
||||
run: |
|
||||
docker pull mlupin/docker-lambda:python3.11
|
||||
- name: Test ServerMode/Coverage
|
||||
env:
|
||||
TEST_SERVER_MODE: ${{ true }}
|
||||
|
2
Makefile
2
Makefile
@ -39,7 +39,7 @@ test-only:
|
||||
pytest -sv -rs --cov=moto --cov-report xml ./tests/ $(TEST_EXCLUDE)
|
||||
# https://github.com/aws/aws-xray-sdk-python/issues/196 - Run these tests separately without Coverage enabled
|
||||
pytest -sv -rs ./tests/test_xray
|
||||
MOTO_CALL_RESET_API=false pytest -rs --cov=moto --cov-report xml --cov-append -n 4 $(PARALLEL_TESTS)
|
||||
MOTO_CALL_RESET_API=false pytest -sv --cov=moto --cov-report xml --cov-append -n 4 $(PARALLEL_TESTS) --dist loadscope
|
||||
|
||||
test: lint test-only
|
||||
|
||||
|
@ -1450,7 +1450,7 @@ class LambdaStorage(object):
|
||||
def all(self) -> Iterable[LambdaFunction]:
|
||||
result = []
|
||||
|
||||
for function_group in self._functions.values():
|
||||
for function_group in list(self._functions.values()):
|
||||
latest = copy.deepcopy(function_group["latest"])
|
||||
latest.function_arn = f"{latest.function_arn}:$LATEST"
|
||||
result.append(latest)
|
||||
|
@ -108,7 +108,7 @@ template = """{
|
||||
"Arn"
|
||||
]
|
||||
},
|
||||
"Runtime": "python2.7",
|
||||
"Runtime": "python3.11",
|
||||
"Timeout": 6
|
||||
},
|
||||
"DependsOn": [
|
||||
|
@ -21,6 +21,7 @@ from .utilities import (
|
||||
_process_lambda,
|
||||
)
|
||||
|
||||
PYTHON_VERSION = "python3.11"
|
||||
_lambda_region = "us-west-2"
|
||||
boto3.setup_default_session(region_name=_lambda_region)
|
||||
|
||||
@ -44,7 +45,7 @@ def test_list_functions():
|
||||
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -85,7 +86,7 @@ def test_create_based_on_s3_with_missing_bucket():
|
||||
with pytest.raises(ClientError) as exc:
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": "this-bucket-does-not-exist", "S3Key": "test.zip"},
|
||||
@ -123,7 +124,7 @@ def test_create_function_from_aws_bucket():
|
||||
|
||||
result = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -140,7 +141,7 @@ def test_create_function_from_aws_bucket():
|
||||
result["FunctionArn"]
|
||||
== f"arn:aws:lambda:{_lambda_region}:{ACCOUNT_ID}:function:{function_name}"
|
||||
)
|
||||
assert result["Runtime"] == "python2.7"
|
||||
assert result["Runtime"] == PYTHON_VERSION
|
||||
assert result["Handler"] == "lambda_function.lambda_handler"
|
||||
assert result["CodeSha256"] == base64.b64encode(
|
||||
hashlib.sha256(zip_content).digest()
|
||||
@ -156,7 +157,7 @@ def test_create_function_from_zipfile():
|
||||
function_name = str(uuid4())[0:6]
|
||||
result = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
@ -176,7 +177,7 @@ def test_create_function_from_zipfile():
|
||||
"EphemeralStorage": {"Size": 512},
|
||||
"FunctionName": function_name,
|
||||
"FunctionArn": f"arn:aws:lambda:{_lambda_region}:{ACCOUNT_ID}:function:{function_name}",
|
||||
"Runtime": "python2.7",
|
||||
"Runtime": PYTHON_VERSION,
|
||||
"Role": result["Role"],
|
||||
"Handler": "lambda_function.lambda_handler",
|
||||
"CodeSize": len(zip_content),
|
||||
@ -351,7 +352,7 @@ def test_create_function__with_tracingmode(tracing_mode):
|
||||
function_name = str(uuid4())[0:6]
|
||||
kwargs = dict(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
@ -536,7 +537,7 @@ def test_get_function():
|
||||
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -570,7 +571,7 @@ def test_get_function():
|
||||
assert result["Configuration"]["Handler"] == "lambda_function.lambda_handler"
|
||||
assert result["Configuration"]["MemorySize"] == 128
|
||||
assert result["Configuration"]["Role"] == get_role_name()
|
||||
assert result["Configuration"]["Runtime"] == "python2.7"
|
||||
assert result["Configuration"]["Runtime"] == PYTHON_VERSION
|
||||
assert result["Configuration"]["Timeout"] == 3
|
||||
assert result["Configuration"]["Version"] == "$LATEST"
|
||||
assert "VpcConfig" in result["Configuration"]
|
||||
@ -612,7 +613,7 @@ def test_get_function_configuration(key):
|
||||
|
||||
fxn = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -636,7 +637,7 @@ def test_get_function_configuration(key):
|
||||
assert result["Handler"] == "lambda_function.lambda_handler"
|
||||
assert result["MemorySize"] == 128
|
||||
assert result["Role"] == get_role_name()
|
||||
assert result["Runtime"] == "python2.7"
|
||||
assert result["Runtime"] == PYTHON_VERSION
|
||||
assert result["Timeout"] == 3
|
||||
assert result["Version"] == "$LATEST"
|
||||
assert "VpcConfig" in result
|
||||
@ -677,7 +678,7 @@ def test_get_function_code_signing_config(key):
|
||||
|
||||
fxn = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -708,7 +709,7 @@ def test_get_function_by_arn():
|
||||
|
||||
fnc = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -739,7 +740,7 @@ def test_delete_function():
|
||||
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -779,7 +780,7 @@ def test_delete_function_by_arn():
|
||||
|
||||
fnc = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -842,7 +843,7 @@ def test_publish():
|
||||
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -903,7 +904,7 @@ def test_list_create_list_get_delete_list():
|
||||
function_name = function_name
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -928,7 +929,7 @@ def test_list_create_list_get_delete_list():
|
||||
"Handler": "lambda_function.lambda_handler",
|
||||
"MemorySize": 128,
|
||||
"Role": get_role_name(),
|
||||
"Runtime": "python2.7",
|
||||
"Runtime": PYTHON_VERSION,
|
||||
"Timeout": 3,
|
||||
"Version": "$LATEST",
|
||||
"VpcConfig": {"SecurityGroupIds": [], "SubnetIds": []},
|
||||
@ -1003,7 +1004,7 @@ def test_get_function_created_with_zipfile():
|
||||
zip_content = get_test_zip_file1()
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
@ -1036,7 +1037,7 @@ def test_get_function_created_with_zipfile():
|
||||
assert config["Handler"] == "lambda_function.handler"
|
||||
assert config["MemorySize"] == 128
|
||||
assert config["Role"] == get_role_name()
|
||||
assert config["Runtime"] == "python2.7"
|
||||
assert config["Runtime"] == PYTHON_VERSION
|
||||
assert config["Timeout"] == 3
|
||||
assert config["Version"] == "$LATEST"
|
||||
assert config["State"] == "Active"
|
||||
@ -1061,7 +1062,7 @@ def test_list_versions_by_function():
|
||||
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -1091,7 +1092,7 @@ def test_list_versions_by_function():
|
||||
|
||||
conn.create_function(
|
||||
FunctionName="testFunction_2",
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -1126,7 +1127,7 @@ def test_list_aliases():
|
||||
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -1138,7 +1139,7 @@ def test_list_aliases():
|
||||
|
||||
conn.create_function(
|
||||
FunctionName=function_name2,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -1226,7 +1227,7 @@ def test_create_function_with_already_exists():
|
||||
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -1239,7 +1240,7 @@ def test_create_function_with_already_exists():
|
||||
with pytest.raises(ClientError) as exc:
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -1280,7 +1281,7 @@ def test_update_configuration(key):
|
||||
|
||||
fxn = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -1295,7 +1296,7 @@ def test_update_configuration(key):
|
||||
assert fxn["Description"] == "test lambda function"
|
||||
assert fxn["Handler"] == "lambda_function.lambda_handler"
|
||||
assert fxn["MemorySize"] == 128
|
||||
assert fxn["Runtime"] == "python2.7"
|
||||
assert fxn["Runtime"] == PYTHON_VERSION
|
||||
assert fxn["Timeout"] == 3
|
||||
|
||||
updated_config = conn.update_function_configuration(
|
||||
@ -1334,7 +1335,7 @@ def test_update_function_zip(key):
|
||||
|
||||
fxn = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": zip_content_one},
|
||||
@ -1416,7 +1417,7 @@ def test_update_function_s3():
|
||||
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -1552,7 +1553,7 @@ def test_remove_unknown_permission_throws_error():
|
||||
function_name = str(uuid4())[0:6]
|
||||
f = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=(get_role_name()),
|
||||
Handler="lambda_function.handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
@ -1574,7 +1575,7 @@ def test_multiple_qualifiers():
|
||||
fn_name = str(uuid4())[0:6]
|
||||
client.create_function(
|
||||
FunctionName=fn_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=(get_role_name()),
|
||||
Handler="lambda_function.handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
@ -1651,7 +1652,7 @@ def test_put_function_concurrency_success():
|
||||
function_name = str(uuid4())[0:6]
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
@ -1676,7 +1677,7 @@ def test_put_function_concurrency_not_enforced():
|
||||
function_name = str(uuid4())[0:6]
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
@ -1705,7 +1706,7 @@ def test_put_function_concurrency_failure():
|
||||
function_name = str(uuid4())[0:6]
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
@ -1740,7 +1741,7 @@ def test_put_function_concurrency_i_can_has_math():
|
||||
function_name_2 = str(uuid4())[0:6]
|
||||
conn.create_function(
|
||||
FunctionName=function_name_1,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
@ -1751,7 +1752,7 @@ def test_put_function_concurrency_i_can_has_math():
|
||||
)
|
||||
conn.create_function(
|
||||
FunctionName=function_name_2,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
|
@ -15,6 +15,7 @@ from .utilities import (
|
||||
|
||||
# See our Development Tips on writing tests for hints on how to write good tests:
|
||||
# http://docs.getmoto.org/en/latest/docs/contributing/development_tips/tests.html
|
||||
PYTHON_VERSION = "python3.11"
|
||||
|
||||
|
||||
@mock_lambda
|
||||
@ -24,7 +25,7 @@ def test_create_alias():
|
||||
|
||||
client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -52,7 +53,7 @@ def test_create_alias_with_routing_config():
|
||||
|
||||
client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -78,7 +79,7 @@ def test_create_alias_using_function_arn():
|
||||
|
||||
fn = client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -104,7 +105,7 @@ def test_delete_alias():
|
||||
|
||||
client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -129,7 +130,7 @@ def test_get_alias():
|
||||
|
||||
client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -159,14 +160,14 @@ def test_aliases_are_unique_per_function():
|
||||
|
||||
client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
)
|
||||
client.create_function(
|
||||
FunctionName=function_name2,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -208,7 +209,7 @@ def test_get_alias_using_function_arn():
|
||||
|
||||
fn = client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -238,7 +239,7 @@ def test_get_alias_using_alias_arn():
|
||||
|
||||
client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -268,7 +269,7 @@ def test_get_unknown_alias():
|
||||
|
||||
client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -291,7 +292,7 @@ def test_update_alias():
|
||||
|
||||
client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -331,7 +332,7 @@ def test_update_alias_errors_if_version_doesnt_exist():
|
||||
|
||||
client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -363,7 +364,7 @@ def test_update_alias_routingconfig():
|
||||
|
||||
client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -399,7 +400,7 @@ def test_get_function_using_alias():
|
||||
|
||||
client.create_function(
|
||||
FunctionName=fn_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
|
@ -5,6 +5,7 @@ from moto import mock_lambda
|
||||
from uuid import uuid4
|
||||
from .utilities import get_role_name, get_test_zip_file1
|
||||
|
||||
PYTHON_VERSION = "python3.11"
|
||||
_lambda_region = "us-west-2"
|
||||
boto3.setup_default_session(region_name=_lambda_region)
|
||||
|
||||
@ -18,7 +19,7 @@ def test_put_function_concurrency(key):
|
||||
conn = boto3.client("lambda", _lambda_region)
|
||||
f = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=(get_role_name()),
|
||||
Handler="lambda_function.handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -43,7 +44,7 @@ def test_delete_function_concurrency(key):
|
||||
conn = boto3.client("lambda", _lambda_region)
|
||||
f = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=(get_role_name()),
|
||||
Handler="lambda_function.handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -72,7 +73,7 @@ def test_get_function_concurrency(key):
|
||||
conn = boto3.client("lambda", _lambda_region)
|
||||
f = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=(get_role_name()),
|
||||
Handler="lambda_function.handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
|
@ -15,6 +15,7 @@ from .utilities import (
|
||||
)
|
||||
from ..markers import requires_docker
|
||||
|
||||
PYTHON_VERSION = "python3.11"
|
||||
_lambda_region = "us-west-2"
|
||||
boto3.setup_default_session(region_name=_lambda_region)
|
||||
|
||||
@ -30,7 +31,7 @@ def test_create_event_source_mapping():
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file3()},
|
||||
@ -63,7 +64,7 @@ def test_invoke_function_from_sqs(key):
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file3()},
|
||||
@ -118,7 +119,7 @@ def test_invoke_function_from_dynamodb_put():
|
||||
function_name = str(uuid4())[0:6]
|
||||
func = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file3()},
|
||||
@ -174,7 +175,7 @@ def test_invoke_function_from_dynamodb_update():
|
||||
function_name = str(uuid4())[0:6]
|
||||
func = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file3()},
|
||||
@ -227,7 +228,7 @@ def test_invoke_function_from_sqs_exception():
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file_error()},
|
||||
@ -295,7 +296,7 @@ def test_invoke_function_from_sns():
|
||||
function_name = str(uuid4())[0:6]
|
||||
result = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file3()},
|
||||
@ -348,7 +349,7 @@ def test_list_event_source_mappings():
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file3()},
|
||||
@ -381,7 +382,7 @@ def test_get_event_source_mapping():
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file3()},
|
||||
@ -411,7 +412,7 @@ def test_update_event_source_mapping():
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func1 = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file3()},
|
||||
@ -422,7 +423,7 @@ def test_update_event_source_mapping():
|
||||
)
|
||||
func2 = conn.create_function(
|
||||
FunctionName="testFunction2",
|
||||
Runtime="python3.8",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file3()},
|
||||
@ -457,7 +458,7 @@ def test_delete_event_source_mapping():
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func1 = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file3()},
|
||||
|
@ -5,6 +5,8 @@ from moto import mock_lambda
|
||||
from uuid import uuid4
|
||||
from .utilities import get_test_zip_file1, get_role_name
|
||||
|
||||
PYTHON_VERSION = "python3.11"
|
||||
|
||||
|
||||
@mock_lambda
|
||||
@pytest.mark.parametrize("key", ["FunctionName", "FunctionArn"])
|
||||
@ -13,7 +15,7 @@ def test_create_function_url_config(key):
|
||||
function_name = str(uuid4())[0:6]
|
||||
fxn = client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -39,7 +41,7 @@ def test_create_function_url_config_with_cors():
|
||||
function_name = str(uuid4())[0:6]
|
||||
fxn = client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -74,7 +76,7 @@ def test_update_function_url_config_with_cors():
|
||||
function_name = str(uuid4())[0:6]
|
||||
fxn = client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -107,7 +109,7 @@ def test_delete_function_url_config(key):
|
||||
function_name = str(uuid4())[0:6]
|
||||
fxn = client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
|
@ -1,9 +1,7 @@
|
||||
import base64
|
||||
import boto3
|
||||
import io
|
||||
import json
|
||||
import pytest
|
||||
import zipfile
|
||||
|
||||
from botocore.exceptions import ClientError
|
||||
from moto import mock_lambda, mock_ec2, settings
|
||||
@ -21,131 +19,167 @@ from .utilities import (
|
||||
)
|
||||
from ..markers import requires_docker
|
||||
|
||||
PYTHON_VERSION = "python3.11"
|
||||
_lambda_region = "us-west-2"
|
||||
|
||||
|
||||
@pytest.mark.network
|
||||
@mock_lambda
|
||||
@requires_docker
|
||||
def test_invoke_function_that_throws_error():
|
||||
conn = boto3.client("lambda", _lambda_region)
|
||||
function_name = str(uuid4())[0:6]
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file_error()},
|
||||
)
|
||||
class TestLambdaInvocations_Error:
|
||||
mock = mock_lambda()
|
||||
|
||||
failure_response = conn.invoke(
|
||||
FunctionName=function_name, Payload=json.dumps({}), LogType="Tail"
|
||||
)
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
cls.mock.start()
|
||||
cls.client = boto3.client("lambda", _lambda_region)
|
||||
cls.function_name = str(uuid4())[0:6]
|
||||
cls.client.create_function(
|
||||
FunctionName=cls.function_name,
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file_error()},
|
||||
)
|
||||
|
||||
assert failure_response["FunctionError"] == "Handled"
|
||||
@classmethod
|
||||
def teardown_class(cls):
|
||||
try:
|
||||
cls.mock.stop()
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
payload = failure_response["Payload"].read().decode("utf-8")
|
||||
payload = json.loads(payload)
|
||||
assert payload["errorType"] == "Exception"
|
||||
assert payload["errorMessage"] == "I failed!"
|
||||
assert "stackTrace" in payload
|
||||
@pytest.mark.parametrize("invocation_type", [None, "RequestResponse"])
|
||||
def test_invoke_function_that_throws_error(self, invocation_type):
|
||||
kw = {"LogType": "Tail"}
|
||||
if invocation_type:
|
||||
kw["InvocationType"] = invocation_type
|
||||
|
||||
logs = base64.b64decode(failure_response["LogResult"]).decode("utf-8")
|
||||
assert "START RequestId:" in logs
|
||||
assert "I failed!" in logs
|
||||
assert "Traceback (most recent call last):" in logs
|
||||
assert "END RequestId:" in logs
|
||||
failure_response = TestLambdaInvocations_Error.client.invoke(
|
||||
FunctionName=self.function_name, Payload=json.dumps({}), **kw
|
||||
)
|
||||
|
||||
assert failure_response["FunctionError"] == "Handled"
|
||||
|
||||
payload = failure_response["Payload"].read().decode("utf-8")
|
||||
payload = json.loads(payload)
|
||||
assert payload["errorType"] == "Exception"
|
||||
assert payload["errorMessage"] == "I failed!"
|
||||
assert "stackTrace" in payload
|
||||
|
||||
logs = base64.b64decode(failure_response["LogResult"]).decode("utf-8")
|
||||
assert "START RequestId:" in logs
|
||||
assert "I failed!" in logs
|
||||
assert "Traceback (most recent call last):" in logs
|
||||
assert "END RequestId:" in logs
|
||||
|
||||
|
||||
@pytest.mark.network
|
||||
@pytest.mark.parametrize("invocation_type", [None, "RequestResponse"])
|
||||
@pytest.mark.parametrize("key", ["FunctionName", "FunctionArn"])
|
||||
@mock_lambda
|
||||
@requires_docker
|
||||
def test_invoke_requestresponse_function(invocation_type, key):
|
||||
conn = boto3.client("lambda", _lambda_region)
|
||||
function_name = str(uuid4())[0:6]
|
||||
fxn = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
Description="test lambda function",
|
||||
Timeout=3,
|
||||
MemorySize=128,
|
||||
Publish=True,
|
||||
)
|
||||
name_or_arn = fxn[key]
|
||||
class TestLambdaInvocations:
|
||||
mock = mock_lambda()
|
||||
|
||||
# Only add invocation-type keyword-argument when provided, otherwise the request
|
||||
# fails to be validated
|
||||
kw = {}
|
||||
if invocation_type:
|
||||
kw["InvocationType"] = invocation_type
|
||||
@classmethod
|
||||
def setup_class(cls):
|
||||
cls.mock.start()
|
||||
cls.client = boto3.client("lambda", _lambda_region)
|
||||
cls.function_name = str(uuid4())[0:6]
|
||||
cls.fxn = cls.client.create_function(
|
||||
FunctionName=cls.function_name,
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
Description="test lambda function",
|
||||
Timeout=3,
|
||||
MemorySize=128,
|
||||
Publish=True,
|
||||
)
|
||||
|
||||
in_data = {"msg": "So long and thanks for all the fish"}
|
||||
success_result = conn.invoke(
|
||||
FunctionName=name_or_arn, Payload=json.dumps(in_data), LogType="Tail", **kw
|
||||
)
|
||||
@classmethod
|
||||
def teardown_class(cls):
|
||||
try:
|
||||
cls.mock.stop()
|
||||
except RuntimeError:
|
||||
pass
|
||||
|
||||
if "FunctionError" in success_result:
|
||||
assert False, success_result["Payload"].read().decode("utf-8")
|
||||
@pytest.mark.parametrize("invocation_type", [None, "RequestResponse"])
|
||||
@pytest.mark.parametrize("key", ["FunctionName", "FunctionArn"])
|
||||
def test_invoke_requestresponse_function(self, invocation_type, key):
|
||||
name_or_arn = self.fxn[key]
|
||||
|
||||
assert success_result["StatusCode"] == 200
|
||||
assert (
|
||||
success_result["ResponseMetadata"]["HTTPHeaders"]["content-type"]
|
||||
== "application/json"
|
||||
)
|
||||
logs = base64.b64decode(success_result["LogResult"]).decode("utf-8")
|
||||
# Only add invocation-type keyword-argument when provided, otherwise the request
|
||||
# fails to be validated
|
||||
kw = {}
|
||||
if invocation_type:
|
||||
kw["InvocationType"] = invocation_type
|
||||
|
||||
assert "START RequestId:" in logs
|
||||
assert "custom log event" in logs
|
||||
assert "END RequestId:" in logs
|
||||
in_data = {"msg": "So long and thanks for all the fish"}
|
||||
success_result = self.client.invoke(
|
||||
FunctionName=name_or_arn, Payload=json.dumps(in_data), LogType="Tail", **kw
|
||||
)
|
||||
|
||||
payload = success_result["Payload"].read().decode("utf-8")
|
||||
assert json.loads(payload) == in_data
|
||||
if "FunctionError" in success_result:
|
||||
assert False, success_result["Payload"].read().decode("utf-8")
|
||||
|
||||
# Logs should not be returned by default, only when the LogType-param is supplied
|
||||
success_result = conn.invoke(
|
||||
FunctionName=name_or_arn, Payload=json.dumps(in_data), **kw
|
||||
)
|
||||
assert success_result["StatusCode"] == 200
|
||||
assert (
|
||||
success_result["ResponseMetadata"]["HTTPHeaders"]["content-type"]
|
||||
== "application/json"
|
||||
)
|
||||
logs = base64.b64decode(success_result["LogResult"]).decode("utf-8")
|
||||
|
||||
assert success_result["StatusCode"] == 200
|
||||
assert (
|
||||
success_result["ResponseMetadata"]["HTTPHeaders"]["content-type"]
|
||||
== "application/json"
|
||||
)
|
||||
assert "LogResult" not in success_result
|
||||
assert "START RequestId:" in logs
|
||||
assert "custom log event" in logs
|
||||
assert "END RequestId:" in logs
|
||||
|
||||
payload = success_result["Payload"].read().decode("utf-8")
|
||||
assert json.loads(payload) == in_data
|
||||
|
||||
@pytest.mark.network
|
||||
@mock_lambda
|
||||
@requires_docker
|
||||
def test_invoke_event_function():
|
||||
conn = boto3.client("lambda", _lambda_region)
|
||||
function_name = str(uuid4())[0:6]
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.9",
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
Description="test lambda function",
|
||||
Timeout=3,
|
||||
MemorySize=128,
|
||||
Publish=True,
|
||||
)
|
||||
# Logs should not be returned by default, only when the LogType-param is supplied
|
||||
success_result = self.client.invoke(
|
||||
FunctionName=name_or_arn, Payload=json.dumps(in_data), **kw
|
||||
)
|
||||
|
||||
with pytest.raises(ClientError):
|
||||
conn.invoke(FunctionName="notAFunction", InvocationType="Event", Payload="{}")
|
||||
assert success_result["StatusCode"] == 200
|
||||
assert (
|
||||
success_result["ResponseMetadata"]["HTTPHeaders"]["content-type"]
|
||||
== "application/json"
|
||||
)
|
||||
assert "LogResult" not in success_result
|
||||
|
||||
in_data = {"msg": "So long and thanks for all the fish"}
|
||||
success_result = conn.invoke(
|
||||
FunctionName=function_name, InvocationType="Event", Payload=json.dumps(in_data)
|
||||
)
|
||||
assert success_result["StatusCode"] == 202
|
||||
assert json.loads(success_result["Payload"].read().decode("utf-8")) == in_data
|
||||
def test_invoke_event_function(self):
|
||||
with pytest.raises(ClientError):
|
||||
self.client.invoke(
|
||||
FunctionName="notAFunction", InvocationType="Event", Payload="{}"
|
||||
)
|
||||
|
||||
in_data = {"msg": "So long and thanks for all the fish"}
|
||||
success_result = self.client.invoke(
|
||||
FunctionName=self.function_name,
|
||||
InvocationType="Event",
|
||||
Payload=json.dumps(in_data),
|
||||
)
|
||||
assert success_result["StatusCode"] == 202
|
||||
assert json.loads(success_result["Payload"].read().decode("utf-8")) == in_data
|
||||
|
||||
def test_invoke_dryrun_function(self):
|
||||
in_data = {"msg": "So long and thanks for all the fish"}
|
||||
success_result = self.client.invoke(
|
||||
FunctionName=self.function_name,
|
||||
InvocationType="DryRun",
|
||||
Payload=json.dumps(in_data),
|
||||
)
|
||||
assert success_result["StatusCode"] == 204
|
||||
|
||||
@pytest.mark.parametrize("key", ["FunctionName", "FunctionArn"])
|
||||
def test_invoke_async_function(self, key):
|
||||
name_or_arn = self.fxn[key]
|
||||
|
||||
success_result = self.client.invoke_async(
|
||||
FunctionName=name_or_arn, InvokeArgs=json.dumps({"test": "event"})
|
||||
)
|
||||
|
||||
assert success_result["Status"] == 202
|
||||
|
||||
|
||||
@pytest.mark.network
|
||||
@ -157,7 +191,7 @@ def test_invoke_lambda_using_environment_port():
|
||||
function_name = str(uuid4())[0:6]
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_lambda_using_environment_port()},
|
||||
@ -196,7 +230,7 @@ def test_invoke_lambda_using_networkmode():
|
||||
function_name = str(uuid4())[0:6]
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_lambda_using_network_mode()},
|
||||
@ -220,7 +254,7 @@ def test_invoke_function_with_multiple_files_in_zip():
|
||||
function_name = str(uuid4())[0:6]
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_zip_with_multiple_files()},
|
||||
@ -239,34 +273,6 @@ def test_invoke_function_with_multiple_files_in_zip():
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.network
|
||||
@mock_lambda
|
||||
@requires_docker
|
||||
def test_invoke_dryrun_function():
|
||||
conn = boto3.client("lambda", _lambda_region)
|
||||
function_name = str(uuid4())[0:6]
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
Description="test lambda function",
|
||||
Timeout=3,
|
||||
MemorySize=128,
|
||||
Publish=True,
|
||||
)
|
||||
|
||||
with pytest.raises(ClientError):
|
||||
conn.invoke(FunctionName="notAFunction", InvocationType="Event", Payload="{}")
|
||||
|
||||
in_data = {"msg": "So long and thanks for all the fish"}
|
||||
success_result = conn.invoke(
|
||||
FunctionName=function_name, InvocationType="DryRun", Payload=json.dumps(in_data)
|
||||
)
|
||||
assert success_result["StatusCode"] == 204
|
||||
|
||||
|
||||
if settings.TEST_SERVER_MODE:
|
||||
|
||||
@mock_ec2
|
||||
@ -280,7 +286,7 @@ if settings.TEST_SERVER_MODE:
|
||||
function_name = str(uuid4())[0:6]
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file2()},
|
||||
@ -305,74 +311,13 @@ if settings.TEST_SERVER_MODE:
|
||||
@pytest.mark.network
|
||||
@mock_lambda
|
||||
@requires_docker
|
||||
def test_invoke_lambda_error():
|
||||
lambda_fx = """
|
||||
def lambda_handler(event, context):
|
||||
raise Exception('failsauce')
|
||||
"""
|
||||
zip_output = io.BytesIO()
|
||||
zip_file = zipfile.ZipFile(zip_output, "w", zipfile.ZIP_DEFLATED)
|
||||
zip_file.writestr("lambda_function.py", lambda_fx)
|
||||
zip_file.close()
|
||||
zip_output.seek(0)
|
||||
|
||||
client = boto3.client("lambda", region_name="us-east-1")
|
||||
client.create_function(
|
||||
FunctionName="test-lambda-fx",
|
||||
Runtime="python3.8",
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Description="test lambda function",
|
||||
Timeout=3,
|
||||
MemorySize=128,
|
||||
Publish=True,
|
||||
Code={"ZipFile": zip_output.read()},
|
||||
)
|
||||
|
||||
result = client.invoke(
|
||||
FunctionName="test-lambda-fx", InvocationType="RequestResponse", LogType="Tail"
|
||||
)
|
||||
|
||||
assert "FunctionError" in result
|
||||
assert result["FunctionError"] == "Handled"
|
||||
|
||||
|
||||
@pytest.mark.network
|
||||
@pytest.mark.parametrize("key", ["FunctionName", "FunctionArn"])
|
||||
@mock_lambda
|
||||
@requires_docker
|
||||
def test_invoke_async_function(key):
|
||||
conn = boto3.client("lambda", _lambda_region)
|
||||
function_name = str(uuid4())[0:6]
|
||||
fxn = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.8",
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
Description="test lambda function",
|
||||
Timeout=3,
|
||||
MemorySize=128,
|
||||
Publish=True,
|
||||
)
|
||||
name_or_arn = fxn[key]
|
||||
|
||||
success_result = conn.invoke_async(
|
||||
FunctionName=name_or_arn, InvokeArgs=json.dumps({"test": "event"})
|
||||
)
|
||||
|
||||
assert success_result["Status"] == 202
|
||||
|
||||
|
||||
@pytest.mark.network
|
||||
@mock_lambda
|
||||
@requires_docker
|
||||
@pytest.mark.xfail(message="Fails intermittently - functionality exists though")
|
||||
def test_invoke_function_large_response():
|
||||
# AWS Lambda should only return bodies smaller than 6 MB
|
||||
conn = boto3.client("lambda", _lambda_region)
|
||||
fxn = conn.create_function(
|
||||
FunctionName=str(uuid4())[0:6],
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_largeresponse()},
|
||||
|
@ -9,6 +9,7 @@ from uuid import uuid4
|
||||
|
||||
from .utilities import get_role_name, get_test_zip_file1
|
||||
|
||||
PYTHON_VERSION = "python3.11"
|
||||
_lambda_region = "us-west-2"
|
||||
boto3.setup_default_session(region_name=_lambda_region)
|
||||
|
||||
@ -87,7 +88,7 @@ def test_get_lambda_layers():
|
||||
function_name = str(uuid4())[0:6]
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -119,7 +120,7 @@ def test_get_lambda_layers():
|
||||
with pytest.raises(ClientError) as exc:
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
|
@ -8,6 +8,7 @@ from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
|
||||
from uuid import uuid4
|
||||
from .utilities import get_role_name, get_test_zip_file1, get_test_zip_file2
|
||||
|
||||
PYTHON_VERSION = "python3.11"
|
||||
_lambda_region = "us-west-2"
|
||||
boto3.setup_default_session(region_name=_lambda_region)
|
||||
|
||||
@ -23,7 +24,7 @@ def test_add_function_permission(key):
|
||||
function_name = str(uuid4())[0:6]
|
||||
f = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=(get_role_name()),
|
||||
Handler="lambda_function.handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
@ -54,7 +55,7 @@ def test_add_permission_with_principalorgid():
|
||||
function_name = str(uuid4())[0:6]
|
||||
fn_arn = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=(get_role_name()),
|
||||
Handler="lambda_function.handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
@ -85,7 +86,7 @@ def test_get_function_policy(key):
|
||||
function_name = str(uuid4())[0:6]
|
||||
f = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
@ -124,7 +125,7 @@ def test_get_policy_with_qualifier():
|
||||
function_name = str(uuid4())[0:6]
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
@ -169,7 +170,7 @@ def test_add_permission_with_unknown_qualifier():
|
||||
function_name = str(uuid4())[0:6]
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
@ -204,7 +205,7 @@ def test_remove_function_permission(key):
|
||||
function_name = str(uuid4())[0:6]
|
||||
f = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=(get_role_name()),
|
||||
Handler="lambda_function.handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
@ -234,7 +235,7 @@ def test_remove_function_permission__with_qualifier(key):
|
||||
function_name = str(uuid4())[0:6]
|
||||
f = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=(get_role_name()),
|
||||
Handler="lambda_function.handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
|
@ -7,6 +7,7 @@ from moto.core import DEFAULT_ACCOUNT_ID as ACCOUNT_ID
|
||||
from uuid import uuid4
|
||||
from .utilities import get_role_name, get_test_zip_file2
|
||||
|
||||
PYTHON_VERSION = "python3.11"
|
||||
_lambda_region = "us-east-1"
|
||||
boto3.setup_default_session(region_name=_lambda_region)
|
||||
|
||||
@ -28,7 +29,7 @@ def test_tags():
|
||||
|
||||
function = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
@ -80,7 +81,7 @@ def test_create_function_with_tags():
|
||||
|
||||
function = conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime=PYTHON_VERSION,
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.handler",
|
||||
Code={"S3Bucket": bucket_name, "S3Key": "test.zip"},
|
||||
|
@ -152,7 +152,7 @@ def create_invalid_lambda(role):
|
||||
with pytest.raises(ClientError) as err:
|
||||
conn.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python2.7",
|
||||
Runtime="python3.11",
|
||||
Role=role,
|
||||
Handler="lambda_function.handler",
|
||||
Code={"ZipFile": zip_content},
|
||||
|
@ -2209,7 +2209,7 @@ def test_create_stack_lambda_and_dynamodb():
|
||||
"FunctionName": "func1",
|
||||
"Handler": "handler.handler",
|
||||
"Role": get_role_name(),
|
||||
"Runtime": "python2.7",
|
||||
"Runtime": "python3.11",
|
||||
"Description": "descr",
|
||||
"MemorySize": 12345,
|
||||
},
|
||||
|
@ -199,7 +199,7 @@ def lambda_handler(event, context):
|
||||
"Description": "Test function",
|
||||
"MemorySize": 128,
|
||||
"Role": {"Fn::GetAtt": ["MyRole", "Arn"]},
|
||||
"Runtime": "python2.7",
|
||||
"Runtime": "python3.11",
|
||||
"Environment": {"Variables": {"TEST_ENV_KEY": "test-env-val"}},
|
||||
"ReservedConcurrentExecutions": 10,
|
||||
},
|
||||
@ -231,7 +231,7 @@ def lambda_handler(event, context):
|
||||
assert result["Functions"][0]["Description"] == "Test function"
|
||||
assert result["Functions"][0]["Handler"] == "index.lambda_handler"
|
||||
assert result["Functions"][0]["MemorySize"] == 128
|
||||
assert result["Functions"][0]["Runtime"] == "python2.7"
|
||||
assert result["Functions"][0]["Runtime"] == "python3.11"
|
||||
assert result["Functions"][0]["Environment"] == {
|
||||
"Variables": {"TEST_ENV_KEY": "test-env-val"}
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ def create_lambda_for_config_rule():
|
||||
lambda_client = boto3.client("lambda", region_name=TEST_REGION)
|
||||
lambda_client.create_function(
|
||||
FunctionName="test_config_rule",
|
||||
Runtime="python3.8",
|
||||
Runtime="python3.11",
|
||||
Role=lambda_role,
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": zipped_lambda_function()},
|
||||
|
@ -26,7 +26,7 @@ def test_creating_bucket__invokes_lambda():
|
||||
|
||||
func = lambda_client.create_function(
|
||||
FunctionName="foobar",
|
||||
Runtime="python3.8",
|
||||
Runtime="python3.11",
|
||||
Role=role["Arn"],
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -107,7 +107,7 @@ def test_create_disabled_rule():
|
||||
|
||||
func = lambda_client.create_function(
|
||||
FunctionName="foobar",
|
||||
Runtime="python3.8",
|
||||
Runtime="python3.11",
|
||||
Role=role["Arn"],
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -235,7 +235,7 @@ def test_creating_bucket__but_invoke_lambda_on_create_object():
|
||||
|
||||
func = lambda_client.create_function(
|
||||
FunctionName="foobar",
|
||||
Runtime="python3.8",
|
||||
Runtime="python3.11",
|
||||
Role=role["Arn"],
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
|
@ -31,7 +31,7 @@ def test_put_subscription_filter_update():
|
||||
)
|
||||
function_arn = client_lambda.create_function(
|
||||
FunctionName="test",
|
||||
Runtime="python3.8",
|
||||
Runtime="python3.11",
|
||||
Role=_get_role_name(region_name),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": _get_test_zip_file()},
|
||||
@ -122,7 +122,7 @@ def test_put_subscription_filter_with_lambda():
|
||||
)
|
||||
function_arn = client_lambda.create_function(
|
||||
FunctionName="test",
|
||||
Runtime="python3.8",
|
||||
Runtime="python3.11",
|
||||
Role=_get_role_name(region_name),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": _get_test_zip_file()},
|
||||
@ -204,7 +204,7 @@ def test_subscription_filter_applies_to_new_streams():
|
||||
client_logs.create_log_group(logGroupName=log_group_name)
|
||||
function_arn = client_lambda.create_function(
|
||||
FunctionName="test",
|
||||
Runtime="python3.8",
|
||||
Runtime="python3.11",
|
||||
Role=_get_role_name(region_name),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": _get_test_zip_file()},
|
||||
@ -420,7 +420,7 @@ def test_delete_subscription_filter():
|
||||
client_logs.create_log_group(logGroupName=log_group_name)
|
||||
function_arn = client_lambda.create_function(
|
||||
FunctionName="test",
|
||||
Runtime="python3.8",
|
||||
Runtime="python3.11",
|
||||
Role=_get_role_name(region_name),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": _get_test_zip_file()},
|
||||
@ -455,7 +455,7 @@ def test_delete_subscription_filter_errors():
|
||||
client_logs.create_log_group(logGroupName=log_group_name)
|
||||
function_arn = client_lambda.create_function(
|
||||
FunctionName="test",
|
||||
Runtime="python3.8",
|
||||
Runtime="python3.11",
|
||||
Role=_get_role_name(region_name),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": _get_test_zip_file()},
|
||||
@ -508,7 +508,7 @@ def test_put_subscription_filter_errors():
|
||||
client_lambda = boto3.client("lambda", "us-east-1")
|
||||
function_arn = client_lambda.create_function(
|
||||
FunctionName="test",
|
||||
Runtime="python3.8",
|
||||
Runtime="python3.11",
|
||||
Role=_get_role_name("us-east-1"),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": _get_test_zip_file()},
|
||||
|
@ -94,8 +94,8 @@ def test_get_query_results():
|
||||
# Only find events from last 2 minutes
|
||||
query_id = client.start_query(
|
||||
logGroupName="test",
|
||||
startTime=int(unix_time(datetime.utcnow() - timedelta(minutes=2))),
|
||||
endTime=int(unix_time(datetime.utcnow())),
|
||||
startTime=int(unix_time(datetime.utcnow() - timedelta(minutes=2, seconds=1))),
|
||||
endTime=int(unix_time(datetime.utcnow() - timedelta(seconds=1))),
|
||||
queryString="fields @message",
|
||||
)["queryId"]
|
||||
|
||||
|
@ -613,7 +613,7 @@ def test_get_resources_lambda():
|
||||
# create one lambda without tags
|
||||
client.create_function(
|
||||
FunctionName="lambda-no-tag",
|
||||
Runtime="python2.7",
|
||||
Runtime="python3.11",
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": zipfile},
|
||||
@ -626,7 +626,7 @@ def test_get_resources_lambda():
|
||||
# create second & third lambda with tags
|
||||
circle_arn = client.create_function(
|
||||
FunctionName="lambda-tag-value-1",
|
||||
Runtime="python2.7",
|
||||
Runtime="python3.11",
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": zipfile},
|
||||
@ -639,7 +639,7 @@ def test_get_resources_lambda():
|
||||
|
||||
rectangle_arn = client.create_function(
|
||||
FunctionName="lambda-tag-value-2",
|
||||
Runtime="python2.7",
|
||||
Runtime="python3.11",
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": zipfile},
|
||||
|
@ -43,7 +43,7 @@ def test_objectcreated_put__invokes_lambda(match_events, actual_event):
|
||||
function_name = str(uuid4())[0:6]
|
||||
fn_arn = lambda_client.create_function(
|
||||
FunctionName=function_name,
|
||||
Runtime="python3.7",
|
||||
Runtime="python3.11",
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file_print_event()},
|
||||
|
@ -774,7 +774,7 @@ def test_cancel_rotate_secret():
|
||||
)
|
||||
func = lambda_conn.create_function(
|
||||
FunctionName="testFunction",
|
||||
Runtime="python3.8",
|
||||
Runtime="python3.11",
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_rotation_zip_file()},
|
||||
@ -1039,7 +1039,7 @@ if settings.TEST_SERVER_MODE:
|
||||
)
|
||||
func = lambda_conn.create_function(
|
||||
FunctionName="testFunction",
|
||||
Runtime="python3.8",
|
||||
Runtime="python3.11",
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_rotation_zip_file()},
|
||||
|
@ -469,7 +469,7 @@ if not settings.TEST_SERVER_MODE:
|
||||
FunctionName="testFunction",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Runtime="python2.7",
|
||||
Runtime="python3.11",
|
||||
Role=role["Role"]["Arn"],
|
||||
)
|
||||
|
||||
|
@ -1932,7 +1932,7 @@ def test_delete_message_batch_with_invalid_receipt_id():
|
||||
def test_message_attributes_in_receive_message():
|
||||
sqs = boto3.resource("sqs", region_name="us-east-1")
|
||||
conn = boto3.client("sqs", region_name="us-east-1")
|
||||
q_resp = conn.create_queue(QueueName="test-queue")
|
||||
q_resp = conn.create_queue(QueueName=str(uuid4())[0:6])
|
||||
queue = sqs.Queue(q_resp["QueueUrl"])
|
||||
|
||||
body_one = "this is a test message"
|
||||
@ -3203,7 +3203,7 @@ def test_message_delay_is_more_than_15_minutes():
|
||||
@mock_sqs
|
||||
def test_receive_message_that_becomes_visible_while_long_polling():
|
||||
sqs = boto3.resource("sqs", region_name="us-east-1")
|
||||
queue = sqs.create_queue(QueueName="test-queue")
|
||||
queue = sqs.create_queue(QueueName=str(uuid4())[0:6])
|
||||
msg_body = str(uuid4())
|
||||
queue.send_message(MessageBody=msg_body)
|
||||
messages = queue.receive_messages()
|
||||
|
@ -24,7 +24,7 @@ def test_invoke_function_from_sqs_queue():
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func = conn.create_function(
|
||||
FunctionName=fn_name,
|
||||
Runtime="python2.7",
|
||||
Runtime="python3.11",
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file1()},
|
||||
@ -95,7 +95,7 @@ def test_invoke_function_from_sqs_fifo_queue():
|
||||
conn = boto3.client("lambda", region_name="us-east-1")
|
||||
func = conn.create_function(
|
||||
FunctionName=fn_name,
|
||||
Runtime="python3.7",
|
||||
Runtime="python3.11",
|
||||
Role=get_role_name(),
|
||||
Handler="lambda_function.lambda_handler",
|
||||
Code={"ZipFile": get_test_zip_file_print_event()},
|
||||
|
Loading…
Reference in New Issue
Block a user