From d712a98ce1b941cdbe5b5b820d4aa42a8b2b91c9 Mon Sep 17 00:00:00 2001 From: Brian Pandola Date: Fri, 8 Jan 2021 06:22:12 -0800 Subject: [PATCH] Enable AWSLambda and STS mocking for AWS China regions/endpoints (#3574) Fixes #3570 --- moto/awslambda/urls.py | 2 +- moto/sts/urls.py | 2 +- tests/test_awslambda/test_lambda.py | 8 ++++++++ tests/test_sts/test_sts.py | 8 ++++++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/moto/awslambda/urls.py b/moto/awslambda/urls.py index 03cedc5e4..a55517e27 100644 --- a/moto/awslambda/urls.py +++ b/moto/awslambda/urls.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals from .responses import LambdaResponse -url_bases = ["https?://lambda.(.+).amazonaws.com"] +url_bases = ["https?://lambda.(.+).amazonaws.com(|.cn)"] response = LambdaResponse() diff --git a/moto/sts/urls.py b/moto/sts/urls.py index e110f39df..031fd9b04 100644 --- a/moto/sts/urls.py +++ b/moto/sts/urls.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals from .responses import TokenResponse -url_bases = ["https?://sts(.*).amazonaws.com"] +url_bases = ["https?://sts(.*).amazonaws.com(|.cn)"] url_paths = {"{0}/$": TokenResponse.dispatch} diff --git a/tests/test_awslambda/test_lambda.py b/tests/test_awslambda/test_lambda.py index 8308195fb..ce46e650a 100644 --- a/tests/test_awslambda/test_lambda.py +++ b/tests/test_awslambda/test_lambda.py @@ -86,6 +86,14 @@ def lambda_handler(event, context): return _process_lambda(pfunc) +@pytest.mark.parametrize("region", ["us-west-2", "cn-northwest-1"]) +@mock_lambda +def test_lambda_regions(region): + client = boto3.client("lambda", region_name=region) + resp = client.list_functions() + resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200) + + @mock_lambda def test_list_functions(): conn = boto3.client("lambda", _lambda_region) diff --git a/tests/test_sts/test_sts.py b/tests/test_sts/test_sts.py index c0324d9f4..3ac0a4b7a 100644 --- a/tests/test_sts/test_sts.py +++ b/tests/test_sts/test_sts.py @@ -741,3 +741,11 @@ def test_federation_token_with_too_long_policy(): ex.value.response["Error"]["Message"].should.contain( str(MAX_FEDERATION_TOKEN_POLICY_LENGTH) ) + + +@pytest.mark.parametrize("region", ["us-west-2", "cn-northwest-1"]) +@mock_sts +def test_sts_regions(region): + client = boto3.client("sts", region_name=region) + resp = client.get_caller_identity() + resp["ResponseMetadata"]["HTTPStatusCode"].should.equal(200)