Paths for local AWS Swift Lambda not working

I have already successfully set up a local, AWS Swift Lambda testing environment. I can invoke the lambda by sending a POST request to http://localhost:7000/invoke with a body formatted as a APIGateway.V2.Request object. That works properly.

Here is the payload that works properly:

{
    "routeKey":"",
    "version":"",
    "rawPath":"",
    "body": "{\"email\": \"test@gmail.com\", \"password\": \"password\",\"device_token\": \"a device token\" }",
    "requestContext":{
        "accountId":"",
        "apiId":"",
        "domainName":"",
        "domainPrefix":"",
        "stage": "",
        "requestId": "",
        "http":{
            "path":"/api/v1/user/login",
            "method":"",
            "protocol":"",
            "sourceIp":"",
            "userAgent":""
        },
        "time": "",
        "timeEpoch":0
    },
    "isBase64Encoded":false,
    "rawQueryString":"",
    "headers":{}
}

The problem arises when I try to invoke the lambda at the path http://localhost:7000/invoke/api/v1/user/login; as this is the path — aside from the base URL — that the iOS app would use to interact with the lambda in production. When I do this I get a "404 Not Found" error.

What this means is that when I test the app locally and I change the base URL from the app's domain name to http://localhost:7000/invoke/, all of the requests will fail, as the app will apply the specific endpoint to the base URL, but the local lambda will refuse interaction with it.

How do I enable a local AWS Swift Lambda to support more than just the default /invoke path?

Hello @chrisbia

When using local testing with http://localhost:7000/invoke , the endpoint is the one of the Swift Lambda Runtime, not your service. It simulates an invocation from the AWS Lambda service to the runtime.

This is not specific to Lambda functions behind an API gateway, whatever is the trigger (SQS, S3, a scheduler, a REST API), the AWS Lambda service and the runtime communicate through a REST API.

If you want to expose your function as a REST API, you have to create an API Gateway in front of it. The API Gateway will take care of decoding the paramaters and passing the JSON you showed to your function.