Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implement Websocket authorizer lambda #734

Closed
Sandy-Garrido opened this issue Nov 24, 2023 · 2 comments
Closed

How to implement Websocket authorizer lambda #734

Sandy-Garrido opened this issue Nov 24, 2023 · 2 comments

Comments

@Sandy-Garrido
Copy link

Sandy-Garrido commented Nov 24, 2023

You'll have to excuse my knowledge here but from my understanding, if a websocket request comes in, it would be converted to a http event but I've tried may different approaches but I can't seem to get it to work.

Initially, I built it as a http request authorizer with the below code, but I don't think this works the same way for an apigateway socket connect authorizer request.

Is there anything from the default set up that cargo lambda new gives that I must do to access the token?
Any help is appreciated (My rust knowledge is fairly low at the moment so this isn't helping)

async fn function_handler(event: Request) -> Result<Response<Body>, Error> {}


#[tokio::main]
async fn main() -> Result<(), Error> {
    tracing_subscriber
        ::fmt()
        .with_max_level(tracing::Level::INFO)
        .with_target(false)
        .without_time()
        .init();

    run(service_fn(function_handler)).await
}

ps. I have omited the rest of the authorizer code as I don't think it's relevant as I'm just getting the following error and none of my logs

ERROR Lambda runtime invoke{requestId="-----" xrayTraceId="Root=1-xxxxxx;Parent=xxxxxx;Sampled=0;Lineage=xxxxxx:0"}:
DeserializeError { inner: Error { path: Path { segments: [] }, original: 
Error("this function expects a JSON payload from Amazon API Gateway, Amazon Elastic Load Balancer,
or AWS Lambda Function URLs, but the data doesn't match any of those services' events", line: 0, column: 0) } }
@Sandy-Garrido
Copy link
Author

Okay, I solved it :D

use lambda_http::{ service_fn, Error };
use lambda_runtime::LambdaEvent;

async fn function_handler(event: LambdaEvent<MyAuthorizerEventStruct>) -> Result<AuthResponse, Error> {
 // My authorizer code
}

async fn main() -> Result<(), Error> {
    tracing_subscriber
        ::fmt()
        .with_max_level(tracing::Level::INFO)
        // disable printing the name of the module in every log line.
        .with_target(false)
        // disabling time is handy because CloudWatch will add the ingestion time.
        .without_time()
        .init();

    lambda_runtime::run(service_fn(function_handler)).await?;
    Ok(())
}

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for the maintainers of this repository to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant