Title: bug: Localstack errors when running two lambdas in debug session · Issue #8522 · localstack/localstack · GitHub
Open Graph Title: bug: Localstack errors when running two lambdas in debug session · Issue #8522 · localstack/localstack
X Title: bug: Localstack errors when running two lambdas in debug session · Issue #8522 · localstack/localstack
Description: Is there an existing issue for this? I have searched the existing issues Current Behavior I have a lambda set up behind an API Gateway that dumps a message on an SQS queue on every request. All that works fine, including the debugging in...
Open Graph Description: Is there an existing issue for this? I have searched the existing issues Current Behavior I have a lambda set up behind an API Gateway that dumps a message on an SQS queue on every request. All tha...
X Description: Is there an existing issue for this? I have searched the existing issues Current Behavior I have a lambda set up behind an API Gateway that dumps a message on an SQS queue on every request. All tha...
Opengraph URL: https://github.com/localstack/localstack/issues/8522
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"bug: Localstack errors when running two lambdas in debug session","articleBody":"### Is there an existing issue for this?\r\n\r\n- [X] I have searched the existing issues\r\n\r\n### Current Behavior\r\n\r\nI have a lambda set up behind an API Gateway that dumps a message on an SQS queue on every request. All that works fine, including the debugging in VS Code with NodeJS. However, the queue consumer lambda isn't getting hit until the API Lambda spinsdown/timesout, then the consumer will be debugged, but then the API Lambda can't be debugged or restarted until the consumer spinsdown/timesout.\r\n\r\n### Expected Behavior\r\n\r\nI expect both breakpoints to be hit. \r\n\r\n### How are you starting LocalStack?\r\n\r\nWith a docker-compose file\r\n\r\n### Steps To Reproduce\r\n\r\nHere is the source code: \r\nCDK:\r\n```typescript\r\nimport * as cdk from 'aws-cdk-lib';\r\nimport { Construct } from 'constructs';\r\nimport * as sqs from 'aws-cdk-lib/aws-sqs';\r\nimport * as lambda from \"aws-cdk-lib/aws-lambda\";\r\nimport * as apigw from \"aws-cdk-lib/aws-apigateway\";\r\nimport { SqsEventSource } from 'aws-cdk-lib/aws-lambda-event-sources';\r\n\r\nexport class TestStack extends cdk.Stack {\r\n constructor(scope: Construct, id: string, props?: cdk.StackProps) {\r\n super(scope, id, props);\r\n\r\n const queue = new sqs.Queue(this, 'TestQueue', {\r\n visibilityTimeout: cdk.Duration.seconds(300)\r\n });\r\n\r\n const hello = new lambda.Function(this, \"HelloHandler\", {\r\n runtime: lambda.Runtime.NODEJS_18_X,\r\n code: lambda.Code.fromAsset(\"lambda\"),\r\n timeout: cdk.Duration.minutes(2),\r\n handler: \"hello.handler\",\r\n environment: {\r\n QUEUE_URL: queue.queueUrl,\r\n QUEUE_NAME: queue.queueName,\r\n }\r\n });\r\n\r\n const consumer = new lambda.Function(this, \"ConsumerHandler\", {\r\n runtime: lambda.Runtime.NODEJS_18_X,\r\n code: lambda.Code.fromAsset(\"lambda\"),\r\n timeout: cdk.Duration.minutes(2),\r\n functionName: \"ConsumerHandler\",\r\n handler: \"consumer.handle\"\r\n });\r\n\r\n consumer.addEventSource(new SqsEventSource(queue))\r\n\r\n new apigw.LambdaRestApi(this, \"Endpoint\", {\r\n handler: hello,\r\n });\r\n\r\n // example resource\r\n queue.grantConsumeMessages(consumer);\r\n queue.grantSendMessages(hello);\r\n }\r\n}\r\n\r\n```\r\nhello.ts (API Lambda)\r\n```typescript\r\nimport { APIGatewayProxyEvent, APIGatewayProxyResult, Context } from 'aws-lambda';\r\nimport { SQS, SendMessageCommandOutput } from \"@aws-sdk/client-sqs\"\r\n\r\nconsole.log(\"Starting API\")\r\n\r\nif(!process.env.QUEUE_URL) throw new Error(\"QUEUE_URL not set!\");\r\nif(!process.env.QUEUE_NAME) throw new Error(\"QUEUE_NAME not set!\");\r\n\r\nconst QUEUE_URL = process.env.QUEUE_URL\r\nconst QUEUE_NAME = process.env.QUEUE_NAME\r\n\r\nexport async function handler(event: APIGatewayProxyEvent, context: Context): Promise\u003cAPIGatewayProxyResult> {\r\n console.log(\"API request received:\", JSON.stringify(event, undefined, 2));\r\n\r\n var sqs = new SQS({endpoint: `http://${process.env.LOCALSTACK_HOSTNAME}:4566`})\r\n const testStr = \"This was sent from the API\"\r\n var params = {\r\n DelaySeconds: 2,\r\n MessageBody: JSON.stringify(testStr),\r\n QueueUrl: `http://${process.env.LOCALSTACK_HOSTNAME}:4566/000000000000/${QUEUE_NAME}`\r\n };\r\n\r\n sqs.sendMessage(params, function (err:any, data: SendMessageCommandOutput | undefined) {\r\n if (err) {\r\n console.log(\"Error\", err);\r\n } else {\r\n console.log(\"Success\", data?.MessageId);\r\n }\r\n });\r\n\r\n return {\r\n statusCode: 200,\r\n headers: { \"Content-Type\": \"text/plain\" },\r\n body: `Hello, CDK! You've hit ${event.path}\\n`\r\n };\r\n}\r\n```\r\n\r\nconsumer.ts\r\n```typescript\r\nimport { SQSEvent, Context } from 'aws-lambda';\r\n\r\nconsole.log(\"Starting Consumer\")\r\n\r\nexport async function handle(event: SQSEvent, context: Context): Promise\u003cvoid> {\r\n console.log(\"Queue Consumer Received Message:\", JSON.stringify(EventTarget));\r\n\r\n}\r\n```\r\nThis is the error I am seeing: \r\n```\r\n2023-06-16T15:31:21.409 DEBUG --- [er:$LATEST_0] l.u.c.docker_sdk_client : Starting container localstack-main-lambda-consumerhandler-453acf0f3e14948e56440cc3a90bea07\r\n2023-06-16T15:31:21.470 WARN --- [er:$LATEST_0] l.s.a.i.runtime_environmen : Failed to start runtime environment for ID=453acf0f3e14948e56440cc3a90bea07 with: \r\nTraceback (most recent call last):\r\n File \"/opt/code/localstack/.venv/lib/python3.10/site-packages/docker/api/client.py\", line 268, in _raise_for_status\r\n response.raise_for_status()\r\n File \"/opt/code/localstack/.venv/lib/python3.10/site-packages/requests/models.py\", line 1021, in raise_for_status\r\n raise HTTPError(http_error_msg, response=self)\r\nrequests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http+docker://localhost/v1.41/containers/aa40a914a5128dda5cf8077f7244817869c0dcc29098aa18929be6f10a8690fb/start\r\nThe above exception was the direct cause of the following exception:\r\nTraceback (most recent call last):\r\n File \"/opt/code/localstack/localstack/utils/container_utils/docker_sdk_client.py\", line 568, in start_container\r\n container.start()\r\n File \"/opt/code/localstack/.venv/lib/python3.10/site-packages/docker/models/containers.py\", line 405, in start\r\n return self.client.api.start(self.id, **kwargs)\r\n File \"/opt/code/localstack/.venv/lib/python3.10/site-packages/docker/utils/decorators.py\", line 19, in wrapped\r\n return f(self, resource_id, *args, **kwargs)\r\n File \"/opt/code/localstack/.venv/lib/python3.10/site-packages/docker/api/container.py\", line 1126, in start\r\n self._raise_for_status(res)\r\n File \"/opt/code/localstack/.venv/lib/python3.10/site-packages/docker/api/client.py\", line 270, in _raise_for_status\r\n raise create_api_error_from_http_exception(e) from e\r\n File \"/opt/code/localstack/.venv/lib/python3.10/site-packages/docker/errors.py\", line 39, in create_api_error_from_http_exception\r\n raise cls(e, response=response, explanation=explanation) from e\r\ndocker.errors.APIError: 500 Server Error for http+docker://localhost/v1.41/containers/aa40a914a5128dda5cf8077f7244817869c0dcc29098aa18929be6f10a8690fb/start: Internal Server Error (\"driver failed programming external connectivity on endpoint localstack-main-lambda-consumerhandler-453acf0f3e14948e56440cc3a90bea07 (69e7c30a80ea6cf486fe57538a185a1d68d2ccdfd2a89ede0e92f60a18d76027): Bind for 0.0.0.0:9229 failed: port is already allocated\")\r\nThe above exception was the direct cause of the following exception:\r\nTraceback (most recent call last):\r\n File \"/opt/code/localstack/localstack/services/awslambda/invocation/runtime_environment.py\", line 172, in start\r\n self.runtime_executor.start(self.get_environment_variables())\r\n File \"/opt/code/localstack/localstack/services/awslambda/invocation/docker_runtime_executor.py\", line 340, in start\r\n CONTAINER_CLIENT.start_container(self.container_name)\r\n File \"/opt/code/localstack/localstack/utils/container_utils/docker_sdk_client.py\", line 573, in start_container\r\n raise ContainerException() from e\r\n```\r\n\r\n\r\n### Environment\r\n\r\n```markdown\r\nstart command\r\nDEBUG=1 LAMBDA_DOCKER_FLAGS='-e NODE_OPTIONS=--inspect-brk=0.0.0.0:9229 -p 9229:9229' \\\r\n LAMBDA_REMOTE_DOCKER=0 \\\r\n localstack start -d\r\n```\r\n\r\n\r\n### Anything else?\r\n\r\nBy the looks of it, only one lambda can be debugged at a time. Is this intended? Is there a way to debug the whole flow?","author":{"url":"https://github.com/TheWix","@type":"Person","name":"TheWix"},"datePublished":"2023-06-16T15:46:32Z","url":"https://github.com/localstack/localstack/issues/8522"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:bb67d419-f710-8ac5-7f13-be4c9286d67f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E808:108F64:287D72:354A6D:6B076161 |
| html-safe-nonce | 0a3d6a9a94ebb61e6240f5e1ee0a10a4a4ce02a083c1dea8977394cffcf37804 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODA4OjEwOEY2NDoyODdENzI6MzU0QTZEOjZCMDc2MTYxIiwidmlzaXRvcl9pZCI6IjkwMTI2NjM2MTAyODMzNTI0MTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d4b02cf073e6aa64da66be29fbe5aeef665dfefa4ec337d1979e4233b613102b |
| hovercard-subject-tag | issue:1760883195 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/localstack/localstack/8522/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7d11b2ba00993251d21e036f5902835b23d9deb2b95c2dccefeb4e0cb423b128/localstack/localstack/issues/8522 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7d11b2ba00993251d21e036f5902835b23d9deb2b95c2dccefeb4e0cb423b128/localstack/localstack/issues/8522 |
| og:image:alt | Is there an existing issue for this? I have searched the existing issues Current Behavior I have a lambda set up behind an API Gateway that dumps a message on an SQS queue on every request. All tha... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | TheWix |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7a557ecc960a3ae6e299fc66b0bc9132072f8860191648e6749fee5d3ff00d82 |
| turbo-cache-control | no-preview |
| go-import | github.com/localstack/localstack git https://github.com/localstack/localstack.git |
| octolytics-dimension-user_id | 28732122 |
| octolytics-dimension-user_login | localstack |
| octolytics-dimension-repository_id | 71948498 |
| octolytics-dimension-repository_nwo | localstack/localstack |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 71948498 |
| octolytics-dimension-repository_network_root_nwo | localstack/localstack |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | bd845eb7947c1ed8c850f7ab415a51339d162de3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width