aws / aws/aws-sam-cli

Bug: sam local start-api fails to initialise lambda function containers within podman/toolbox container

Open
#7,298 14 comments 2 reactions 0 assignees View on GitHub
stage/bug-repro
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

### Description:
When attempting to run `sam local start-api` from within podman/toolbox on Fedora 40 Kinoite, the lambda function containers fail to initialise. Command hangs for over an hour (at least) without initialising containers. On one occassion, when left overnight it initialised the container and was ready to be called.

To test, utilised AWS Lambda powertools tutorial template found here: https://docs.powertools.aws.dev/lambda/python/latest/tutorial/#code-example

Output `Initializing the lambda functions containers.`

### Steps to reproduce:
Fedora 40 Kinoite -> Toolbox
```
toolbox create sam-test
toolbox enter sam-test
cd temp
sudo ./sam-installation/install
export DOCKER_HOST=unix:///run/user/1000/podman/podman.sock
sam build && sam local start-api --debug
```

### Observed result:
```
[user@toolbox hello-world-tutorial]$ sam build && sam local start-api --debug
Starting Build use cache
Manifest is not changed for (HelloWorldFunction), running incremental build
Building codeuri: /var/home/user/hello-world-tutorial/hello_world runtime: python3.12 metadata: {} architecture: x86_64
functions: HelloWorldFunction
Running PythonPipBuilder:CopySource
Running PythonPipBuilder:CopySource

Build Succeeded

Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml

Commands you can use next
=========================
[*] Validate SAM template: sam validate
[*] Invoke Function: sam local invoke
[*] Test Function in the Cloud: sam sync --stack-name {{stack-name}} --watch
[*] Deploy: sam deploy --guided
2024-08-01 13:57:06,971 | Config file location: /var/home/user/hello-world-tutorial/samconfig.toml
2024-08-01 13:57:06,973 | Loading configuration values from [default.['local', 'start-api'].parameters] (env.command_name.section) in
config file at '/var/home/user/hello-world-tutorial/samconfig.toml'...
2024-08-01 13:57:06,974 | Configuration values successfully loaded.
2024-08-01 13:57:06,975 | Configuration values are: {'stack_name': 'hello-world-tutorial', 'warm_containers': 'EAGER'}
2024-08-01 13:57:06,978 | Using SAM Template at /var/home/user/hello-world-tutorial/.aws-sam/build/template.yaml
2024-08-01 13:57:07,041 | Using config file: samconfig.toml, config environment: default
2024-08-01 13:57:07,042 | Expand command line arguments to:
2024-08-01 13:57:07,042 | --template_file=/var/home/user/hello-world-tutorial/.aws-sam/build/template.yaml
--host=127.0.0.1 --port=3000 --static_dir=public --layer_cache_basedir=/home/user/.aws-sam/layers-pkg --warm_containers=EAGER
--container_host=localhost --container_host_interface=127.0.0.1
2024-08-01 13:57:07,097 | local start-api command is called
2024-08-01 13:57:08,114 | No Parameters detected in the template
2024-08-01 13:57:08,159 | Sam customer defined id is more priority than other IDs. Customer defined id for resource HelloWorldFunction
is HelloWorldFunction
2024-08-01 13:57:08,160 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the
resource logical id as the resource id
2024-08-01 13:57:08,162 | 0 stacks found in the template
2024-08-01 13:57:08,163 | No Parameters detected in the template
2024-08-01 13:57:08,185 | Sam customer defined id is more priority than other IDs. Customer defined id for resource HelloWorldFunction
is HelloWorldFunction
2024-08-01 13:57:08,186 | There is no customer defined id or cdk path defined for resource ServerlessRestApi, so we will use the
resource logical id as the resource id
2024-08-01 13:57:08,187 | 2 resources found in the stack
2024-08-01 13:57:08,188 | Found Serverless function with name='HelloWorldFunction' and CodeUri='HelloWorldFunction'
2024-08-01 13:57:08,189 | --base-dir is not presented, adjusting uri HelloWorldFunction relative to
/var/home/user/hello-world-tutorial/.aws-sam/build/template.yaml
2024-08-01 13:57:08,191 | watch resource /var/home/user/hello-world-tutorial/.aws-sam/build/template.yaml
2024-08-01 13:57:08,192 | Create Observer for resource /var/home/user/hello-world-tutorial/.aws-sam/build/template.yaml
with recursive True
2024-08-01 13:57:08,193 | watch resource /var/home/user/hello-world-tutorial/.aws-sam/build/template.yaml's parent
/var/home/user/hello-world-tutorial/.aws-sam/build
2024-08-01 13:57:08,194 | Create Observer for resource /var/home/user/hello-world-tutorial/.aws-sam/build with recursive
False
2024-08-01 13:57:08,200 | Initializing the lambda functions containers.
2024-08-01 13:57:08,202 | Async execution started
2024-08-01 13:57:08,203 | Invoking function functools.partial(.initialize_function_container at 0x7f23bff07920>,
Function(function_id='HelloWorldFunction', name='HelloWorldFunction', functionname='HelloWorldFunction', runtime='python3.12',
memory=None, timeout=3, handler='app.lambda_handler', imageuri=None, packagetype='Zip', imageconfig=None,
codeuri='/var/home/user/hello-world-tutorial/.aws-sam/build/HelloWorldFunction', environment=None, rolearn=None,
layers=[], events={'HelloWorld': {'Type': 'Api', 'Properties': {'Path': '/hello', 'Method': 'get', 'RestApiId':
'ServerlessRestApi'}}}, metadata={'SamResourceId': 'HelloWorldFunction'}, inlinecode=None, codesign_config_arn=None,
architectures=['x86_64'], function_url_config=None, function_build_info=, stack_path='', runtime_management_config=None, logging_config=None))
2024-08-01 13:57:08,208 | Waiting for async results
```

### Expected result:
```
Building image..........................
2024-08-01 13:32:44 WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
* Running on http://127.0.0.1:3000
* 2024-08-01 13:32:44 Press CTRL+C to quit
```
Expected Lambda to initialise and be available.

### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
OS: Fedora 40 Kinoite
{
"version": "1.120.0",
"system": {
"python": "3.11.8",
"os": "Linux-6.9.10-200.fc40.x86_64-x86_64-with-glibc2.39"
},
"additional_dependencies": {
"docker_engine": "5.1.2",
"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

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.