Skip to content

How can I test locally using sam local start-lambda with a Rust lambda? #589

@shirakaba

Description

@shirakaba

I've set up a lambda with CDK by referring to the repository structure used by rnag/rust.aws-cdk-lambda/cdk-examples/rust-standalone, whilst matching this repo's up-to-date dependencies.

I want to do local testing (run this lambda as a server on localhost and make HTTP GET requests to it), so I've tried running this:

$ sam local start-lambda --port 8011 --template ./cdk.out/RustStandaloneStack.template.json   
Starting the Local Lambda Service. You can now invoke your Lambda Functions defined in your template through the endpoint.
2023-01-23 11:08:56  * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)

The server successfully starts up, but I can't figure out what sort of request to send it. It just responds with a 404 no matter what path or headers I specify to it with my GET requests.

By comparison, one-off invocations work just fine:

# ./tests/sample.json is an event matching the same format of the one seen in this issue comment:
# https://github.com/awslabs/aws-lambda-rust-runtime/issues/365#issue-1054795934
$ sam local invoke MyRustLambda --event ./tests/sample.json --template ./cdk.out/RustStandaloneStack.template.json

Requesting using the exact same path and headers specified in my ./tests/sample.json file, I am met with a 404 response.

This feels like an underdocumented area in the SAM/CDK/Lambda docs so any pointers would be greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions