I'm suffering from a bizarre undocumented HTTP 421 Misdirected Request error when trying to invoke Lambda functions from other Lambda functions via Python/boto3 (with InvocationType = 'Event'
) like so:
lambda_client.invoke(
FunctionName = my_lambda_function,
Payload = json.dumps('{'foo': 'bar'}),
InvocationType = 'Event'
)
The error thrown is:
botocore.exceptions.ClientError: An error occurred (421) when calling the Invoke operation:
(With nothing printed beyond the colon.)
I believe my Lambda permission are in order too, as per below?
Execution role:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
Execution role policy (inline):
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"lambda:InvokeFunction"
],
"Resource": [
"arn:aws:lambda:MY_AWS_REGION:MY_AWS_ACCOUNT_ID:function:MY_LAMBDA_FUNCTION_NAME"
]
}
]
}
Anyone have any idea?
https://docs.aws.amazon.com/lambda/latest/api/API_Invoke.html lists a bunch of possible error codes, but they do not include any mention of HTTP 421
or Misdirected Request
. Worse, Googling "421" Lambda invoke
does not seem to bring up anything relevant at all, either.
I was able to repro the exact same error ClientError: An error occurred (421) when calling the Invoke operation
by passing \n
to FunctionName
:
client.invoke(
FunctionName='MyOtherFunction\n',
InvocationType = 'Event'
)
MyOtherFunction
is the name of the function I want to invoke, and \n
is what I added to repro the error.
So, please make sure you are not passing weird characters to FunctionName
such as \n
or %0a
(new line symbol).