aws-sam-cli: DockerTag does not accept !Ref

Description:

DockerTag does not accept !Ref

Steps to reproduce:

Init a serverless template with lambda using an Image. Set Metadata:

Parameters: GitShaHash: Type: String Default: TEST

Metadata: Dockerfile: Dockerfile DockerContext: ./<function_code> DockerTag: !Ref GitShaHash

Observed result:

In cdk.out template: Metadata: DockerContext: <path_to_lambda_code> DockerTag: GitShaHash Dockerfile: Dockerfile SamResourceId: <resource_id>

Expected result:

Metadata: DockerContext: <path_to_lambda_code> DockerTag: Ref: GitShaHash Dockerfile: Dockerfile SamResourceId: <resource_id> I am using the same parameter to tag the lambda function itself and it works.

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

  1. OS: Windows 11
  2. sam --version: 1.66.0
  3. AWS region: eu-west-2

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

@sachahu1 samconfig.toml is based on commands, so deploy configuration is not read during build. You can either use test.globals.parameters or define properties for test.build.parameters.

Docs: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html

In case this ever ends up helping someone else: I figured out my mistake, the [test.build.parameters] section of the samconfig.toml also allows for parameter_overrides. So to correct the minimal example above, this samconfig.toml works:

version = 0.1

[test]
[test.build]
[test.build.parameters]
parameter_overrides = [
    "DockerImageTag=test"
]

[test.deploy]
[test.deploy.parameters]
stack_name = "test"
confirm_changeset = false
capabilities = ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND"]
parameter_overrides = [
    "Environment=TEST",
]
image_repositories = [
    "TemplateLambda=...",
]