-
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 3000 --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 This feels like an underdocumented area in the SAM/CDK/Lambda docs so any pointers would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I'm not familiar with https://www.cargo-lambda.info/commands/watch.html |
Beta Was this translation helpful? Give feedback.
-
AWS CLI is a simpler way to invoke lambda via this endpoint. More details here. aws lambda invoke --function-name "HelloWorldFunction" --endpoint-url "http://127.0.0.1:3001" --no-verify-ssl out.txt |
Beta Was this translation helpful? Give feedback.
-
Thank you both very much for the timely response that let me get straight back to work! I'll check through @calavera's resources as well in a moment, but @bnusunny's Lambda API docs look like exactly the piece of the puzzle I've been missing. RecapTo recap, I'm trying to translate the following sam local invoke MyRustLambda --event ./tests/sample.json --template ./cdk.out/RustStandaloneStack.template.json ... where {
"requestContext": {
"http": {
"method": "GET"
},
"timeEpoch": 1674445263
}
} Step one:
|
Beta Was this translation helpful? Give feedback.
Thank you both very much for the timely response that let me get straight back to work! I'll check through @calavera's resources as well in a moment, but @bnusunny's Lambda API docs look like exactly the piece of the puzzle I've been missing.
Recap
To recap, I'm trying to translate the following
sam local invoke
to asam local start-lambda
+ HTTP request (for testing a web app):sam local invoke MyRustLambda --event ./tests/sample.json --template ./cdk.out/RustStandaloneStack.template.json
... where
tests/sample.json
could be as complex as this example or as simple as just:Step one:
sam l…