Runtime.HandlerNotFound Error when mountCode: true
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- aws, docker, javascript, nodejs
Research direction
Start by reviewing pull request #215 and the mountCode path used with serverless-esbuild, then reproduce the issue with the provided serverless.yaml and docker-compose.yaml. Use the logged Runtime.HandlerNotFound failure to trace why the mounted handler is unavailable. Done means mountCode:true starts the Lambda successfully and code updates are propagated.
Written by the indexing model from the issue text.
Description
I'm using localstack with a docker setup (localstrack-pro:latest), and when having mountCode:true in my plugin config the lambda container that is being spun up is unable to find the code. When disabled it executes fine but then code updates are not being propagated.
I added the fix of this pull request: #215 locally.
I'm also using serverless-esbuild.
serverless.yaml
service: cms-api
configValidationMode: error
provider:
stackName: ${env:STACK_NAME, 'serverless-framework'}-sls-middleware
name: aws
runtime: nodejs18.x
stage: local
region: ${env:AWS_DEFAULT_REGION, 'eu-central-1'}
environment: ${file(./serverless.yml):provider.environment}
apiGateway:
binaryMediaTypes:
- '*/*'
restApiId: !Ref ApiGateway
restApiRootResourceId:
'Fn::GetAtt':
- ApiGateway
- RootResourceId
plugins:
- serverless-esbuild
- serverless-localstack
custom:
stage: local
esbuild:
bundle: true
minify: false
keepOutputDirectory: true
outputFileExtension: .mjs
format: esm
target: "esnext"
platform: "node"
exclude: ["aws-sdk"]
banner:
js: import { createRequire } from 'module';const require = createRequire(import.meta.url);
localstack:
debug: true
edgePort: 4566
autostart: false
stages: [ local ]
lambda:
mountCode: true
functions:
api: ${file(./serverless.yml):functions.api}
resources:
Resources:
DynamoDBTableCMS: ${file(./serverless.yml):resources.Resources.DynamoDBTableCMS}
ApiGateway:
Type: AWS::ApiGateway::RestApi
Properties:
Name: ApiGateway
Tags:
- Key: _custom_id_
Value: cms-api
docker-compose.yaml
version: "3"
services:
localstack:
container_name: "api-localstack"
build:
context: ./docker/localstack
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
- "127.0.0.1:53:53" # DNS config (only required for Pro)
- "127.0.0.1:53:53/udp" # DNS config (only required for Pro)
- "127.0.0.1:443:443" # LocalStack HTTPS Gateway (only required for Pro)
working_dir: /
environment:
- SERVICES=lambda,s3,sqs,iam,apigateway,dynamodb # SERVICES variable is ignored if EAGER_SERVICE_LOADING=0
- LS_LOG=debug
- PERSISTENCE=1
- BUCKET_MARKER_LOCAL=hot-reload
- LOCALSTACK_API_KEY={redacted} # only required for Pro
- DOCKER_HOST=unix:///var/run/docker.sock
- STACK_NAME=api
- ENVIRONMENT=local
- DYNAMODB_SHARE_DB=1
volumes:
- "./docker/localstack/volume:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
- "./:/app"
When the errors happens it keeps re spawning the lambda container until I stop it.
Logs
api-localstack | 2023-03-31T08:56:57.475 DEBUG --- [pi:$LATEST_0] l.u.c.docker_sdk_client : Creating container with attributes: {'mount_volumes': <localstack.utils.container_utils.container_client.VolumeMappings object at 0x7ff925c23880>, 'ports': None, 'cap_add': None, 'cap_drop': None, 'security_opt': None, 'dns': '127.0.0.1', 'additional_flags': '', 'workdir': None, 'privileged': None, 'labels': None, 'ulimits': None, 'command': None, 'detach': None, 'entrypoint': '/var/rapid/init', 'env_vars': {'AWS_DEFAULT_REGION': 'us-east-1', 'AWS_REGION': 'us-east-1', 'AWS_LAMBDA_FUNCTION_NAME': 'api-local-api', 'AWS_LAMBDA_FUNCTION_MEMORY_SIZE': 1024, 'AWS_LAMBDA_FUNCTION_VERSION': '$LATEST', 'AWS_LAMBDA_INITIALIZATION_TYPE': 'on-demand', 'AWS_LAMBDA_LOG_GROUP_NAME': '/aws/lambda/api-local-api', 'AWS_LAMBDA_LOG_STREAM_NAME': '2023/03/31/[$LATEST]0af9cbe7a820c0ba0db5030e64e1a184', 'AWS_ACCESS_KEY_ID': 'ASIAQAAAAAAADD2Y7UJJ', 'AWS_SECRET_ACCESS_KEY': 'yKdyaQMgFPFCyBv4nPtbiWaYIjrsvq3cV1gPFSl8', 'AWS_SESSION_TOKEN': 'FQoGZXIvYXdzEBYaD/DkcwdRjXJnysJVWiDvT8it86Tfw38AdeGKjio0Af69yx/ZcohR60kbG1Gu07EkxZO/j/s864mi/lgO5ktQrb4XVSn5GlB7gAU4Q2JOmlVCTaTXcnAvbix42UMVfkOfKHp6Prvl9yxB2aPqoy8Z2hXrr3vRAHcWwE9rFYVXn7lTDSCBfb8rLyB19Qfrhnqn35yK4URyJVgVsjHzqp0EtZvxOgSirgSo7U9OJRH/c4luhx3BxOcfyqBKKf3zxRILTx1z8VAT4QTfs7zhMJwpo+1AqWeYByodRP7XUtlRCLwts6nqdlomBDq7DzYdjJSRjSbpgRREFJGMxkDD3xE=', 'LAMBDA_TASK_ROOT': '/var/task', 'LAMBDA_RUNTIME_DIR': '/var/runtime', 'AWS_XRAY_CONTEXT_MISSING': 'LOG_ERROR', 'AWS_XRAY_DAEMON_ADDRESS': '127.0.0.1:2000', '_AWS_XRAY_DAEMON_PORT': '2000', '_AWS_XRAY_DAEMON_ADDRESS': '127.0.0.1', 'TZ': ':UTC', 'AWS_LAMBDA_FUNCTION_TIMEOUT': 6, 'LOCALSTACK_HOSTNAME': '172.30.0.2', 'EDGE_PORT': '443', 'AWS_ENDPOINT_URL': 'http://172.30.0.2:443', 'LOCALSTACK_RUNTIME_ID': '0af9cbe7a820c0ba0db5030e64e1a184', 'LOCALSTACK_RUNTIME_ENDPOINT': 'http://172.30.0.2:443/_localstack_lambda/0af9cbe7a820c0ba0db5030e64e1a184', '_HANDLER': '.esbuild/.build/src/handler/http.handle', 'AWS_EXECUTION_ENV': 'Aws_Lambda_nodejs18.x', 'ENVIRONMENT': 'local', 'LOCALSTACK_HOT_RELOADING_PATHS': '/var/task', 'LOCALSTACK_ENABLE_DNS_SERVER': '1', 'NODE_TLS_REJECT_UNAUTHORIZED': '0'}, 'image_name': 'public.ecr.aws/lambda/nodejs:18', 'interactive': None, 'name': 'api-localstack-lambda-api-local-api-0af9cbe7a820c0ba0db5030e64e1a184', 'network': 'cms_api_default', 'platform': 'linux/amd64', 'remove': None, 'self': <localstack.utils.container_utils.docker_sdk_client.SdkDockerClient object at 0x7ff96b9b6b30>, 'tty': None, 'user': None}
api-localstack | 2023-03-31T08:56:57.518 DEBUG --- [pi:$LATEST_0] localstack.packages.api : Installation of awslambda-runtime skipped (already installed).
api-localstack | 2023-03-31T08:56:57.518 DEBUG --- [pi:$LATEST_0] l.u.c.docker_sdk_client : Copying file /var/lib/localstack/lib/awslambda-runtime/v0.1.16-pre/x86_64/. into api-localstack-lambda-api-local-api-0af9cbe7a820c0ba0db5030e64e1a184:/
api-localstack | 2023-03-31T08:56:57.824 DEBUG --- [pi:$LATEST_0] l.u.c.docker_sdk_client : Starting container api-localstack-lambda-api-local-api-0af9cbe7a820c0ba0db5030e64e1a184
api-localstack | 2023-03-31T08:56:57.827 DEBUG --- [ asgi_gw_0] l.u.c.docker_sdk_client : Removing container: api-localstack-lambda-api-local-api-9de9563801ea86a2fc7cb199626b3200
api-localstack | 2023-03-31T08:56:57.946 INFO --- [ asgi_gw_0] localstack.request.http : POST /_localstack_lambda/9de9563801ea86a2fc7cb199626b3200/status/9de9563801ea86a2fc7cb199626b3200/error => 202
api-localstack | 2023-03-31T08:56:58.250 DEBUG --- [pi:$LATEST_0] l.u.c.container_client : Getting ipv4 address for container api-localstack-lambda-api-local-api-0af9cbe7a820c0ba0db5030e64e1a184 in network cms_api_default.
api-localstack | 2023-03-31T08:56:58.421 WARN --- [ asgi_gw_0] l.s.a.i.executor_endpoint : Execution environment startup failed: {"errorType":"Runtime.HandlerNotFound","errorMessage":".esbuild/.build/src/handler/http.handle is undefined or not exported","trace":["Runtime.HandlerNotFound: .esbuild/.build/src/handler/http.handle is undefined or not exported"," at UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1035:15)"," at async start (file:///var/runtime/index.mjs:1195:23)"," at async file:///var/runtime/index.mjs:1201:1"]}
api-localstack | 2023-03-31T08:56:58.421 DEBUG --- [ asgi_gw_0] l.u.c.docker_sdk_client : Stopping container: api-localstack-lambda-api-local-api-0af9cbe7a820c0ba0db5030e64e1a184
Screenshot of the built code:

Screenshot of the lambda on app.localstack.cloud (this is with mountCode: false)

Screenshot of the lambda on app.localstack.cloud ( this is with mountCode: true)

- Dominant language
- JavaScript
- Stars
- 542
- Forks
- 92
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from localstack/serverless-localstack
-
Difficulty 1/5 Under an hour Newbie friendliness 25/100
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
aws:apigateway status: backlog
Difficulty 4/5 3-5 days Newbie friendliness 35/100
localstack/serverless-localstack#270 · 3 reactions ·
All issues in localstack/serverless-localstack
Similar issues
-
bug customer-eng Durable Agents Inngest status: needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
githubnext/gh-aw-cao#13475 ·
-
[BUG]: "Clear All" in Settings doesn't clear the saved analysis, old data comes back after reload Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
AOSSIE-Org/OrgExplorer#253 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
oxc-project/oxc#26944 ·
-
ai-observability bug team/ai-observability
Difficulty 2/5 1-3 hours Newbie friendliness 78/100