Question: DevContainer use with SAM CLI if DevContainer is a readonly filesystem
- Dominant language
- Python
- Stars
- 6.7k
- Forks
- 1.2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 52
Description
### Description:
When I am in a DevContainer and I cloned the repo using volumes (this is important for the repro) in VS Code, I get an error on Mac when I try to invoke my function.
### Steps to reproduce:
### Observed result:
```
2023-09-30 14:32:59,364 | No config file found in this directory.
2023-09-30 14:32:59,364 | OSError occurred while reading TOML file: [Errno 2] No such file or directory: '/workspaces/redacted/src/apps/redacted/src/.aws-sam/build/samconfig.toml'
2023-09-30 14:32:59,364 | Config file location: /workspaces/redacted/src/apps/redacted/src/.aws-sam/build/samconfig.toml
2023-09-30 14:32:59,365 | Config file '/workspaces/redacted/src/apps/redacted/src/.aws-sam/build/samconfig.toml' does not exist
2023-09-30 14:32:59,378 | Using config file: samconfig.toml, config environment: default
2023-09-30 14:32:59,378 | Expand command line arguments to:
2023-09-30 14:32:59,378 | --template_file=/workspaces/redacted/src/apps/redacted/src/.aws-sam/build/template.yaml --container_env_vars=./.aws-sam/scripts/container-environment.start.json --host=0.0.0.0 --container_host=host.docker.internal --container_host_interface=0.0.0.0 --docker_volume_basedir=/workspaces/redacted/src/apps/redacted/src/.aws-sam/build --port=3000 --static_dir=public --layer_cache_basedir=/root/.aws-sam/layers-pkg
2023-09-30 14:32:59,415 | local start-api command is called
2023-09-30 14:32:59,416 | No Parameters detected in the template
2023-09-30 14:32:59,423 | There is no customer defined id or cdk path defined for resource Lambda, so we will use the resource logical id as the resource id
2023-09-30 14:32:59,423 | There is no customer defined id or cdk path defined for resource ServerlessHttpApi, so we will use the resource logical id as the resource id
2023-09-30 14:32:59,423 | 0 stacks found in the template
2023-09-30 14:32:59,423 | No Parameters detected in the template
2023-09-30 14:32:59,427 | There is no customer defined id or cdk path defined for resource Lambda, so we will use the resource logical id as the resource id
2023-09-30 14:32:59,427 | There is no customer defined id or cdk path defined for resource ServerlessHttpApi, so we will use the resource logical id as the resource id
2023-09-30 14:32:59,427 | 2 resources found in the stack
2023-09-30 14:32:59,427 | Found Serverless function with name='Lambda' and CodeUri='Lambda'
2023-09-30 14:32:59,431 | Found '1' API Events in Serverless function with name 'Lambda'
2023-09-30 14:32:59,431 | Detected Inline Swagger definition
2023-09-30 14:32:59,431 | Parsing Swagger document using 3.0 specification
2023-09-30 14:32:59,431 | Lambda function integration not found in Swagger document at path='/events' method='post'
2023-09-30 14:32:59,431 | Found '0' APIs in resource 'ServerlessHttpApi'
2023-09-30 14:32:59,431 | Found '0' authorizers in resource 'ServerlessHttpApi'
2023-09-30 14:32:59,431 | Removed duplicates from '0' Explicit APIs and '1' Implicit APIs to produce '1' APIs
2023-09-30 14:32:59,431 | 1 APIs found in the template
2023-09-30 14:32:59,435 | Mounting Lambda at http://0.0.0.0:3000/events [POST]
2023-09-30 14:32:59,435 | You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. If you used sam build before running local commands, you will need to re-run sam build for the changes to be picked up. You only need to restart SAM CLI if you update your AWS SAM template
2023-09-30 14:32:59,435 | Localhost server is starting up. Multi-threading = True
2023-09-30 14:32:59 WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on all addresses (0.0.0.0)
* Running on http://127.0.0.1:3000
* Running on http://172.17.0.3:3000
2023-09-30 14:32:59 Press CTRL+C to quit
2023-09-30 14:33:10,293 | Constructed Event Version 2.0 to invoke Lambda. Event: {'version': '2.0', 'routeKey': 'POST /events', 'rawPath': '/events', 'rawQueryString': '', 'cookies': [], 'headers': {'Content-Type': 'application/json', 'User-Agent': 'PostmanRuntime/7.33.0', 'Accept': '*/*', 'Postman-Token': '2259fda0-00ae-45bd-9c5a-498736ea9622', 'Host': 'localhost:3000', 'Accept-Encoding': 'gzip, deflate, br', 'Connection': 'keep-alive', 'Content-Length': '2', 'X-Forwarded-Proto': 'http', 'X-Forwarded-Port': '3000'}, 'requestContext': {'accountId': '123456789012', 'apiId': '1234567890', 'http': {'method': 'POST', 'path': '/events', 'protocol': 'HTTP/1.1', 'sourceIp': '127.0.0.1', 'userAgent': 'Custom User Agent String'}, 'requestId': '3d8d61de-06c4-429f-a65d-2f7a552c83b6', 'routeKey': 'POST /events', 'stage': '$default', 'time': '30/Sep/2023:14:32:59 +0000', 'timeEpoch': 1696084379, 'domainName': 'localhost', 'domainPrefix': 'localhost'}, 'body': '{}', 'pathParameters': {}, 'stageVariables': None, 'isBase64Encoded': False}
2023-09-30 14:33:10,293 | Found one Lambda function with name 'Lambda'
2023-09-30 14:33:10,293 | Invoking app.handler (nodejs18.x)
2023-09-30 14:33:10,294 | No environment variables found for function 'Lambda'
2023-09-30 14:33:10,294 | Loading AWS credentials from session with profile 'None'
2023-09-30 14:33:10,339 | Resolving code path. Cwd=/workspaces/redacted/src/apps/redacted/src/.aws-sam/build, CodeUri=Lambda
2023-09-30 14:33:10,339 | Resolved absolute path to code is /workspaces/redacted/src/apps/fredacted/src/.aws-sam/build/Lambda
2023-09-30 14:33:10,339 | Code /workspaces/redacted/src/apps/redacted/src/.aws-sam/build/Lambda is not a zip/jar file
2023-09-30 14:33:13,566 | Local image is up-to-date
2023-09-30 14:33:13,578 | Using local image: public.ecr.aws/lambda/nodejs:18-rapid-x86_64.
2023-09-30 14:33:13,578 | Mounting /workspaces/redacted/src/apps/redacted/src/.aws-sam/build/Lambda as /var/task:ro,delegated, inside runtime container
2023-09-30 14:33:13,735 | Cleaning all decompressed code dirs
2023-09-30 14:33:13,736 | Exception on /events [POST]
Traceback (most recent call last):
File "/usr/local/lib/python3.11/dist-packages/docker/api/client.py", line 268, in _raise_for_status
response.raise_for_status()
File "/usr/local/lib/python3.11/dist-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error for url: http+docker://localhost/v1.35/containers/f5a343e6333b803ab986effa10d9175621bf3d1fd43883cbb4d1e98e3636f6e9/start
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/flask/app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/samcli/local/apigw/local_apigw_service.py", line 719, in _request_handler
lambda_response = self._invoke_lambda_function(route.function_name, route_lambda_event)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/samcli/local/apigw/local_apigw_service.py", line 612, in _invoke_lambda_function
self.lambda_runner.invoke(lambda_function_name, event_str, stdout=stdout_writer, stderr=self.stderr)
File "/usr/local/lib/python3.11/dist-packages/samcli/commands/local/lib/local_lambda.py", line 144, in invoke
self.local_runtime.invoke(
File "/usr/local/lib/python3.11/dist-packages/samcli/lib/telemetry/metric.py", line 324, in wrapped_func
return_value = func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/samcli/local/lambdafn/runtime.py", line 190, in invoke
container = self.run(container, function_config, debug_context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/samcli/local/lambdafn/runtime.py", line 145, in run
self._container_manager.run(container)
File "/usr/local/lib/python3.11/dist-packages/samcli/local/docker/manager.py", line 117, in run
container.start(input_data=input_data)
File "/usr/local/lib/python3.11/dist-packages/samcli/local/docker/container.py", line 321, in start
raise ex
File "/usr/local/lib/python3.11/dist-packages/samcli/local/docker/container.py", line 317, in start
real_container.start()
File "/usr/local/lib/python3.11/dist-packages/docker/models/containers.py", line 406, in start
return self.client.api.start(self.id, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/docker/utils/decorators.py", line 19, in wrapped
return f(self, resource_id, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/docker/api/container.py", line 1127, in start
self._raise_for_status(res)
File "/usr/local/lib/python3.11/dist-packages/docker/api/client.py", line 270, in _raise_for_status
raise create_api_error_from_http_exception(e) from e
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/dist-packages/docker/errors.py", line 39, in create_api_error_from_http_exception
raise cls(e, response=response, explanation=explanation) from e
docker.errors.APIError: 500 Server Error for http+docker://localhost/v1.35/containers/f5a343e6333b803ab986effa10d9175621bf3d1fd43883cbb4d1e98e3636f6e9/start: Internal Server Error ("error while creating mount source path '/host_mnt/workspaces/redacted/src/apps/redacted/src/.aws-sam/build/Lambda': mkdir /host_mnt/workspaces: read-only file system")
```
### Expected result:
### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
1. OS: M1 Mac
2. `sam --version`: SAM CLI, version 1.97.0
3. AWS region: eu-west-1
```
{
"version": "1.97.0",
"system": {
"python": "3.11.2",
"os": "Linux-5.15.49-linuxkit-pr-aarch64-with-glibc2.36"
},
"additional_dependencies": {
"docker_engine": "24.0.5",
"aws_cdk": "Not available",
"terraform": "Not available"
},
"available_beta_feature_env_vars": [
"SAM_CLI_BETA_FEATURES",
"SAM_CLI_BETA_BUILD_PERFORMANCE",
"SAM_CLI_BETA_TERRAFORM_SUPPORT",
"SAM_CLI_BETA_RUST_CARGO_LAMBDA"
]
}
```
Contributor guide
Assessment
This issue has not been assessed yet.