Skip to content

failed to build request: http::Error(InvalidUri(InvalidFormat)) when testing from API Gateway in the AWS Console #368

Closed
@ionionascu

Description

@ionionascu

When testing from the API Gateway's test method without explicitely providing the Host http header, I get the error failed to build request: http::Error(InvalidUri(InvalidFormat)), which I didn't use to get (maybe the test request has been changed on AWS side).

This test reproduces the error on the current master branch:

#[test]
fn test() {
    const PAYLOAD: &str = r#"{
        "resource": "/test",
        "path": "/test",
        "httpMethod": "POST",
        "headers": {
            "test": "test"
        },
        "multiValueHeaders": {
            "test": [
                "test"
            ]
        },
        "queryStringParameters": {
            "test": "test"
        },
        "multiValueQueryStringParameters": {
            "test": [
                "test"
            ]
        },
        "pathParameters": null,
        "stageVariables": null,
        "requestContext": {
            "resourceId": "resourceId",
            "resourcePath": "/test",
            "operationName": "lambda",
            "httpMethod": "POST",
            "requestTime": "19/Nov/2021:12:19:02 +0000",
            "path": "/test",
            "accountId": "123",
            "protocol": "HTTP/1.1",
            "stage": "test-invoke-stage",
            "domainPrefix": "testPrefix",
            "requestTimeEpoch": 1637324342768,
            "requestId": "123",
            "identity": {
                "cognitoIdentityPoolId": null,
                "cognitoIdentityId": null,
                "apiKey": "test-invoke-api-key",
                "principalOrgId": null,
                "cognitoAuthenticationType": null,
                "userArn": "arn",
                "apiKeyId": "test-invoke-api-key-id",
                "userAgent": "aws-internal/3 aws-sdk-java/1.12.76 Linux/5.4.147-83.259.amzn2int.x86_64 OpenJDK_64-Bit_Server_VM/25.302-b08 java/1.8.0_302 vendor/Oracle_Corporation cfg/retry-mode/standard",
                "accountId": "123",
                "caller": "caller",
                "sourceIp": "test-invoke-source-ip",
                "accessKey": "accessKey",
                "cognitoAuthenticationProvider": null,
                "user": "user"
            },
            "domainName": "testPrefix.testDomainName",
            "apiId": "apiId"
        },
        "body": null,
        "isBase64Encoded": false
    }"#;
    
    let val: lambda_http::request::LambdaRequest = serde_json::from_str(PAYLOAD).unwrap();
    let _http_request: http::Request<Body> = http::Request::from(val);
}

In my case, the error being generated here https://github.com/awslabs/aws-lambda-rust-runtime/blob/master/lambda-http/src/request.rs#L472

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions