aws / aws/aws-sam-cli

SAM Build Not Mounting Lambda Code in `/var/task` During `sam local start api` on Windows

Open
#7,478 13 comments 0 reactions 0 assignees View on GitHub
area/docker platform/windows
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

### Description:
When using `npm run build` and running `sam local start api` or `sam local invoke`, SAM builds the Lambda image on the fly. However, it seems that the Lambda code is not being mounted correctly in `/var/task`, which results in an empty directory. This prevents the Lambda from executing properly.

### Context:
I expect SAM to mount the built Lambda sources from `dist/` into `/var/task` inside the container. However, the `/var/task` directory is empty, making it impossible to execute the Lambda function via `sam local start api`.

I've tried multiple solutions but couldn't resolve this issue. It might be related to switching from a Linux development environment to a Windows environment.

In my `template.yml`, I point the `CodeUri` to the compiled code in the `dist/` directory, like this:

```yaml
CodeUri: dist/lambdas/myFunction/
```

### Expected behavior:
The compiled Lambda code should be mounted into `/var/task` inside the container to allow the Lambda function to execute properly.

### Environment:
- **Operating System**: Windows
- **SAM CLI Version**: Tested with version 1.120
- **Docker Version**: 26.1.0-rd
- **Docker setup**: Running on WSL2
- **Custom Lambda Image**: Defined in `template.yml`

### Steps to reproduce:
1. Run `npm run build`. [npx tsc --project tsconfig.build.json]
2. Start the Lambda function using either `sam local start api` or `sam local invoke`.
3. Inspect the container, and observe that `/var/task` is empty.

### Possible suggestions or fixes:
- Ensure that SAM properly mounts the Lambda code into the `/var/task` directory during execution on Windows.
- Investigate if the issue is related to file mounting differences between Linux and Windows.

Thank you for your help!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.