You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 16, 2023. It is now read-only.
I'm trying to create a custom ApiGatewayV2 authorizer lambda for a WebSocket API using ApiGatewayV2CustomAuthorizerV1Request or ApiGatewayV2CustomAuthorizerV2Request, but the lambda fails to run in both cases.
It runs the main() function with no issues, but code inside the handler_fn is being completely ignored, and no error whatsoever is being thrown. I've tried using other types, such as ApiGatewayCustomAuthorizerRequest, and they work just fine, but they're incompatible with the API Gateway version and return incorrect/missing data.
Sometimes it outputs an "Unknown.Runtime" error message directly in the lambda logs.
I'm using lambda_runtime and aws_lambda_events, both v0.7.0.
I've tried v0.7.1 and v0.7.2 and had the exact same result.
Here's the code:
use aws_lambda_events::apigw::ApiGatewayV2CustomAuthorizerV2Request;use lambda_runtime::{service_fn,Error,LambdaEvent};#[tokio::main]asyncfnmain() -> Result<(),Error>{println!("Running main function");let handler = service_fn(|event| handler_fn(event));
lambda_runtime::run(handler).await?;println!("Finished running");Ok(())}asyncfnhandler_fn(event:LambdaEvent<ApiGatewayV2CustomAuthorizerV2Request>,) -> Result<ApiGatewayV2CustomAuthorizerV2Request,Error>{println!("Query params:");println!("{:#?}", event.payload.query_string_parameters);Ok(event.payload)}
Here are the lambda logs:
2023-01-05T20:53:34.722-03:00 | Running main function
2023-01-05T20:53:34.729-03:00 | START RequestId: e320b0aa-6596-4396-abb5-2989ebfad615 Version: $LATEST
2023-01-05T20:53:34.731-03:00 | END RequestId: e320b0aa-6596-4396-abb5-2989ebfad615
2023-01-05T20:53:34.731-03:00 | REPORT RequestId: e320b0aa-6596-4396-abb5-2989ebfad615 Duration: 1.57 ms Billed
And here's my lambda configuration:
Also, what's the difference between ApiGatewayV2CustomAuthorizerV1Request and ApiGatewayV2CustomAuthorizerV2Request?
Thanks!
The text was updated successfully, but these errors were encountered:
This refers to AWS SAM role issues with APIGateway authorisers (had the exact same issue yesterday!)
In my case, serde was failing to serialise the event payload because some fields from both V1 and V2 types weren't present (such as http_method from V1) and weren't marked as Option<>.
I believe this is happening because I'm using a custom authoriser for a WebSocket API, and some fields are different from HTTP ones.
I believe there's two ways to fix this:
Create a specific type for WebSocket authorisers
Modify the existing types to use Option<> for fields that aren't in both HTTP and WebSocket APIs and maybe add any missing fields
For now, I have created a custom struct with only the fields I'll be using in my lambda
I've used ApiGatewayV2CustomAuthorizerV2Request for an HTTP APIGatewayV2, payload version 2.0, and the API didn't work and the cloudwatch log of $context.authorizer.error recorded
"The Lambda Authorizer function returned the following error: missing field cookies at line 1 column 1439. Check your Lambda function code and try again."
So this issue happens not only for WebSocket API but also when the field is not actually necessary for HTTP API case too. I think adding Option<> is a better solution in short term.
I'm trying to create a custom ApiGatewayV2 authorizer lambda for a WebSocket API using
ApiGatewayV2CustomAuthorizerV1Request
orApiGatewayV2CustomAuthorizerV2Request
, but the lambda fails to run in both cases.It runs the
main()
function with no issues, but code inside thehandler_fn
is being completely ignored, and no error whatsoever is being thrown. I've tried using other types, such asApiGatewayCustomAuthorizerRequest
, and they work just fine, but they're incompatible with the API Gateway version and return incorrect/missing data.Sometimes it outputs an "Unknown.Runtime" error message directly in the lambda logs.
I'm using
lambda_runtime
andaws_lambda_events
, both v0.7.0.I've tried v0.7.1 and v0.7.2 and had the exact same result.
Here's the code:
Here are the lambda logs:
And here's my lambda configuration:
Also, what's the difference between
ApiGatewayV2CustomAuthorizerV1Request
andApiGatewayV2CustomAuthorizerV2Request
?Thanks!
The text was updated successfully, but these errors were encountered: