Fixed issue with Lambda invoke via ARN
- Fixed an issue where Lambda invokes via an ARN was hitting real AWS.
This commit is contained in:
parent
152ad8b82e
commit
bb64258a8f
@ -176,7 +176,8 @@ class LambdaResponse(BaseResponse):
|
||||
def _invoke(self, request, full_url):
|
||||
response_headers = {}
|
||||
|
||||
function_name = self.path.rsplit("/", 2)[-2]
|
||||
# URL Decode in case it's a ARN:
|
||||
function_name = unquote(self.path.rsplit("/", 2)[-2])
|
||||
qualifier = self._get_param("qualifier")
|
||||
|
||||
response_header, payload = self.lambda_backend.invoke(
|
||||
|
@ -12,6 +12,7 @@ url_paths = {
|
||||
r"{0}/(?P<api_version>[^/]+)/event-source-mappings/?$": response.event_source_mappings,
|
||||
r"{0}/(?P<api_version>[^/]+)/event-source-mappings/(?P<UUID>[\w_-]+)/?$": response.event_source_mapping,
|
||||
r"{0}/(?P<api_version>[^/]+)/functions/(?P<function_name>[\w_-]+)/invocations/?$": response.invoke,
|
||||
r"{0}/(?P<api_version>[^/]+)/functions/(?P<resource_arn>.+)/invocations/?$": response.invoke,
|
||||
r"{0}/(?P<api_version>[^/]+)/functions/(?P<function_name>[\w_-]+)/invoke-async/?$": response.invoke_async,
|
||||
r"{0}/(?P<api_version>[^/]+)/tags/(?P<resource_arn>.+)": response.tag,
|
||||
r"{0}/(?P<api_version>[^/]+)/functions/(?P<function_name>[\w_-]+)/policy/(?P<statement_id>[\w_-]+)$": response.policy,
|
||||
|
@ -124,6 +124,43 @@ def test_invoke_requestresponse_function():
|
||||
json.loads(payload).should.equal(in_data)
|
||||
|
||||
|
||||
@mock_lambda
|
||||
def test_invoke_requestresponse_function_with_arn():
|
||||
from moto.awslambda.models import ACCOUNT_ID
|
||||
|
||||
conn = boto3.client("lambda", "us-west-2")
|
||||
conn.create_function(
|
||||
FunctionName="testFunction",
|
||||
Runtime="python2.7",
|
||||
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="arn:aws:lambda:us-west-2:{}:function:testFunction".format(
|
||||
ACCOUNT_ID
|
||||
),
|
||||
InvocationType="RequestResponse",
|
||||
Payload=json.dumps(in_data),
|
||||
)
|
||||
|
||||
success_result["StatusCode"].should.equal(202)
|
||||
result_obj = json.loads(
|
||||
base64.b64decode(success_result["LogResult"]).decode("utf-8")
|
||||
)
|
||||
|
||||
result_obj.should.equal(in_data)
|
||||
|
||||
payload = success_result["Payload"].read().decode("utf-8")
|
||||
json.loads(payload).should.equal(in_data)
|
||||
|
||||
|
||||
@mock_lambda
|
||||
def test_invoke_event_function():
|
||||
conn = boto3.client("lambda", "us-west-2")
|
||||
|
Loading…
Reference in New Issue
Block a user