Skip to content

Use more informative container names for spawned Lambda containers#7667

Merged
thrau merged 1 commit intomasterfrom
lambda-friendly-container-names
Feb 14, 2023
Merged

Use more informative container names for spawned Lambda containers#7667
thrau merged 1 commit intomasterfrom
lambda-friendly-container-names

Conversation

@dominikschubert
Copy link
Member

Motivation

It's quite hard to find the container you're looking for when just looking at the list of running/exited containers right now since we just assign the randomly generated executor ID as a container name and one has to actually check the container metadata/config to find out which lambda is being executed in it.

Resolves #7635

Changes

  • Changed default container name from generic executor ID (e.g. ffa532cb281182ee92052ff97e1f37c4) to the following pattern: <main-container-name>-lambda-<function-name>-<excecutor-id>
    • example: localstack-main-lambda-processing-ffa532cb281182ee92052ff97e1f37c4

Discussion

We could make this more generic in the future by providing a config variable we'll use to format this
e.g. LAMBDA_DOCKER_CONTAINER_NAME_GENERATOR="<main-container-name>-lambda-<region>-<function-name>-<runtime>"
or LAMBDA_DOCKER_CONTAINER_NAME_GENERATOR="<main-container-name>-lambda-<function-arn>"
Still, we'll always add the executor/runtime ID as a suffix

Also open to suggestion of other defaults 👍

@dominikschubert dominikschubert self-assigned this Feb 12, 2023
@dominikschubert dominikschubert temporarily deployed to localstack-ext-tests February 12, 2023 08:00 — with GitHub Actions Inactive
@github-actions
Copy link

LocalStack integration with Pro

       3 files  ±0         3 suites  ±0   1h 29m 46s ⏱️ - 8m 38s
1 695 tests ±0  1 362 ✔️ ±0  333 💤 ±0  0 ±0 
2 409 runs  ±0  1 736 ✔️ ±0  673 💤 ±0  0 ±0 

Results for commit 2a275c0. ± Comparison against base commit 398abb4.

Copy link
Member

@joe4dev joe4dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usability improvement makes a lot of sense 👍
There are different options for container naming (see comment).

Comment on lines +234 to +236
self.function_version.id.function_name.lower(),
]
).replace("_", "-")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to standardize the container names (e.g., lowercase and - only) or make it easier to match for external lookups?

  • _ and capital letters would be valid for container names.
  • _ cannot be used in URLs and might lead to limitations with the DNS re-work (see Simon's post in #sig-localstack)

Docker container names

  • Validation regex: [a-zA-Z0-9][a-zA-Z0-9_.-] (Docker source)
  • Length constraint: There seem to be no explicit length constraints (also see this SO discussion). There might be implicit limits (e.g., 63 chars in GitLab runners due to hitting max DNS hostname length mentioned here)

Input restrictions

  • A Docker container name without length restriction should by definition be a valid input
  • All AWS Lambda functions [a-zA-Z0-9-_]+ should be valid container names (AWS FunctionName docs)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing _ with - was also just partly because we do this in the k8s executor and partly for the DNS reason you mentioned.

As you said, ideally we'd have names that can be used as valid DNS names, although the use case for this is pretty much non-existent for lambda at least and 63 Character is unfortunately also extremely limiting in practice, so we can't encode a lot of information this way. :/

"""
container_name = "-".join(
[
get_main_container_name() or "localstack",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice to handle fallback for host mode 👍

CONTAINER_CLIENT.copy_into_container(self.container_name, source, target)

CONTAINER_CLIENT.start_container(self.id)
CONTAINER_CLIENT.start_container(self.container_name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sidenote: If we want to protect ourselves from external renaming in the future, we could consider using the Container.id / CLI container id instead of the name but the name seems to work fine for now.

@thrau thrau merged commit 14675b0 into master Feb 14, 2023
@thrau thrau deleted the lambda-friendly-container-names branch February 14, 2023 23:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: PROVIDER_OVERRIDE_LAMBDA=asf, Lambda container prefix

3 participants