question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to execute multiple requests in parallel through sam local start-api

See original GitHub issue

Template: AWSTemplateFormatVersion: ‘2010-09-09’ Transform: ‘AWS::Serverless-2016-10-31’ Description: An AWS Serverless Specification template describing your function. Resources: CheckoutLambda: Type: “AWS::Serverless::Function” Properties: Handler: “CheckoutLambda/index.handler” Role: redacted Runtime: “nodejs6.10” Timeout: 300 Environment: Variables: ENV: int Events: CheckoutApi: Type: Api Properties: Path: ‘/checkout/donate’ Method: post Executing two posts in parallel: curl -X POST http://127.0.0.1:3000/checkout/donate -H 'cache-control: no-cache' -H 'content-type: application/json' -H 'postman-token: 9f48e8af-a291-c6c6-6e9f-cc60a358a872' -d '5000' & curl -X POST http://127.0.0.1:3000/checkout/donate -H 'cache-control: no-cache' -H 'content-type: application/json' -H 'postman-token: 9f48e8af-a291-c6c6-6e9f-cc60a358a872' -d '4000' Output from aws sam cli: 2018/02/12 14:42:53 Invoking CheckoutLambda/index.handler (nodejs6.10) 2018/02/12 14:42:53 Invoking CheckoutLambda/index.handler (nodejs6.10) START RequestId: 3c1c1ce5-fb4a-13be-4400-2fc7df6fed59 Version: $LATEST 2018-02-12T22:42:57.276Z 3c1c1ce5-fb4a-13be-4400-2fc7df6fed59 4000 START RequestId: 6d07c29d-da2e-14cc-2d1e-8996b0fccdcf Version: $LATEST 2018-02-12T22:42:57.539Z 6d07c29d-da2e-14cc-2d1e-8996b0fccdcf 5000 END RequestId: 3c1c1ce5-fb4a-13be-4400-2fc7df6fed59 REPORT RequestId: 3c1c1ce5-fb4a-13be-4400-2fc7df6fed59 Duration: 4033.19 ms Billed Duration: 4100 ms Memory Size: 0 MB Max Memory Used: 31 MB 2018/02/12 14:42:59 Function returned an invalid response (must include one of: body, headers or statusCode in the response object): unexpected end of JSON input

Another thing to note is that the function then later times out: 2018/02/12 14:26:05 Function CheckoutLambda/index.handler timed out after 300 seconds

handler(index.js) `function sleepFor( sleepDuration ){ var now = new Date().getTime(); while(new Date().getTime() < now + sleepDuration){ /* do nothing */ } } function formatResponse (statusCode, body) { return { statusCode: statusCode, body: JSON.stringify(body) }; } exports.handler = (event, context, callback) => { console.log(event.body); sleepFor(JSON.parse(event.body));

callback(null, formatResponse(200,‘test’)); };` This is a contrived example that I could share. But I’m running into this problem when trying to create integration tests for my lambda function. Ideally I’d like to be able to execute many tests in parallel against the locally spun-up api so that it mirrors the actual api. Thanks for anyone who looks into this! 😃

PS: Sometimes it works as expected. Race condition?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
jfusscommented, May 30, 2018

Parallel Requests are now completely supported as of v.0.3.0. We even have integ tests that exercise this 😃

Closing as this was addressed.

3reactions
hobotroidcommented, Apr 27, 2018

Yeah it’s really difficult to develop and test an API locally when it can only handle 1 request at a time. That, coupled with the fact that each requests takes 4-8 seconds to complete (container has to spin up for every request), makes the whole process painful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to execute multiple requests in parallel through sam ...
The way I created the docker network was by running docker network create lambda-local and then tried to use sam local start-api --docker- ......
Read more >
Testing Step Functions and AWS SAM CLI Local
With both AWS Step Functions and AWS Lambda running on your local machine, ... Step 1: Set Up AWS SAM; Step 2: Test...
Read more >
Using AWS SAM-CLI requires rebuild every time I update the ...
A great solution to this problem is to use the skip-pull-image flag so that Docker will reuse the Lambda runtime. Essentially run: sam...
Read more >
Invoking AWS Lambda functions locally using AWS SAM CLI
Learn how to invoke AWS Lambda functions on your machine using AWS SAM CLI. ... 2. Run sam --version to verify that you...
Read more >
How to setup a Serverless application with AWS SAM and ...
The work around suggested is to use nodemon and then run nodemon --exec sam build next to the command sam local start-api -d...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found