aws / aws/aws-sam-cli

Bug: AWS::Serverless::Function specified within Fn::ForEach does not have ImageUri set correctly

Open
#9,117 1 comment 0 reactions 0 assignees View on GitHub
type/bug
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

### Description:
template.yaml
```
AWSTemplateFormatVersion: '2010-09-09'
Transform:
- AWS::LanguageExtensions
- AWS::Serverless-2016-10-31
Description: Lambda Function with Fn::ForEach using FuncType parameter

Parameters:
FuncType:
Type: CommaDelimitedList
Default: "func1"
Description: List of function types to create

Resources:
# Another standalone function (not using ForEach)
StandaloneFunction:
Type: AWS::Serverless::Function
Properties:
FunctionName: StandaloneFunction
PackageType: Image
MemorySize: 128
ImageConfig:
Command:
- app.lambda_handler
Environment:
Variables:
FUNCTION_TYPE: standalone
Metadata:
Dockerfile: Dockerfile
DockerContext: ./hello_world
DockerTag: standalone-latest

# Use Fn::ForEach to create multiple Lambda functions based on FuncType parameter
Fn::ForEach::LoopFunction:
- FunctionName
- !Ref FuncType
- '${FunctionName}Function':
Type: AWS::Serverless::Function
Properties:
FunctionName: !Sub '${FunctionName}Function'
PackageType: Image
MemorySize: 128
ImageUri: "foo"
ImageConfig:
Command:
- app.lambda_handler
Environment:
Variables:
FUNCTION_TYPE: !Sub '${FunctionName}'
Metadata:
Dockerfile: Dockerfile
DockerContext: ./hello_world
DockerTag: !Sub '${FunctionName}-latest'
```
samconfig.toml
```
# More information about the configuration file can be found here:
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html
version = 0.1

[default.global.parameters]
stack_name = "fn-foreach-bug"
language_extensions = true

[default.build.parameters]
cached = true
parallel = true

[default.validate.parameters]
lint = true

[default.deploy.parameters]
capabilities = "CAPABILITY_IAM"
confirm_changeset = true
resolve_s3 = true
image_repository = ""

[default.package.parameters]
resolve_s3 = true

[default.sync.parameters]
watch = true

[default.local_start_api.parameters]
warm_containers = "EAGER"

[default.local_start_lambda.parameters]
warm_containers = "EAGER"

```

### Steps to reproduce:

Execute
`sam build`
`sam deploy --debug`

### Observed result:

ImageUri for func1function:func1-latest does not have before it. Upon attempting to deploy, an image not found error is thrown.
```
2026-07-06 13:46:54,587 | 2 resources found in the stack
2026-07-06 13:46:54,588 | Found Serverless function with name='StandaloneFunction' and
ImageUri=':standalonefunction-688312777049-standalone-latest'
2026-07-06 13:46:54,588 | --base-dir is not presented, adjusting uri ./hello_world relative to
/var/folders/f9/037ssx6j50z73x70tvx8s8hw0000gn/T/tmpplkx7u27
2026-07-06 13:46:54,588 | --base-dir is not presented, adjusting uri . relative to
/var/folders/f9/037ssx6j50z73x70tvx8s8hw0000gn/T/tmpplkx7u27
2026-07-06 13:46:54,589 | Found Serverless function with name='func1Function' and
ImageUri='func1function:func1-latest'
```

I have to set `ImageUri: "foo"` on the function definition, otherwise `sam deploy --debug` errors out with

```
Error: Unable to upload artifact None referenced by ImageUri parameter of func1Function resource.
Image not found for ImageUri parameter of func1Function resource.
```

I have also tried with `--image-repositories`, but that errors out too, although in a different way. Am I doing something wrong here or is this a bug?

### Expected result:

is included in the func1function:func1-latest ImageUri.
```
2026-07-06 13:46:54,587 | 2 resources found in the stack
2026-07-06 13:46:54,588 | Found Serverless function with name='StandaloneFunction' and
ImageUri=':standalonefunction-688312777049-standalone-latest'
2026-07-06 13:46:54,588 | --base-dir is not presented, adjusting uri ./hello_world relative to
/var/folders/f9/037ssx6j50z73x70tvx8s8hw0000gn/T/tmpplkx7u27
2026-07-06 13:46:54,588 | --base-dir is not presented, adjusting uri . relative to
/var/folders/f9/037ssx6j50z73x70tvx8s8hw0000gn/T/tmpplkx7u27
2026-07-06 13:46:54,589 | Found Serverless function with name='func1Function' and
ImageUri=':func1function:func1-latest'
```

### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

1. OS:
2. `sam --version`:
3. AWS region:

```
{
"version": "1.162.1",
"system": {
"python": "3.14.6",
"os": "macOS-26.5.1-arm64-arm-64bit-Mach-O"
},
"additional_dependencies": {
"container_engine": "Docker(v28.3.3)",
"aws_cdk": "Not available",
"terraform": "1.15.2"
},
"available_beta_feature_env_vars": [
"SAM_CLI_BETA_FEATURES",
"SAM_CLI_BETA_BUILD_PERFORMANCE",
"SAM_CLI_BETA_TERRAFORM_SUPPORT",
"SAM_CLI_BETA_PACKAGE_PERFORMANCE",
"SAM_CLI_BETA_UV_PACKAGE_MANAGER"
]
}
```

`Add --debug flag to command you are running`

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with template.yaml and samconfig.toml by running sam build and sam deploy --debug. Compare the standalone function with the AWS::Serverless::Function generated through Fn::ForEach, focusing on how ImageUri is formed for the image-based deployment. Done means the generated func1Function ImageUri includes the configured repository URI and deployment no longer reports an image-not-found error.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, docker, python
Domain
cloud, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.