-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lambda: override cmd in DockerImageFunctionProps #30330
Comments
Now that I understand the code involved, there are some design questions to resolve first. imageConfig: undefinedIfNoKeys({
command: code.image?.cmd,
entryPoint: code.image?.entrypoint,
workingDirectory: code.image?.workingDirectory,
}),
I propose a new interface called /**
* Docker image options
**/
export interface ImageConfig {
/**
* Specify or override the CMD on the specified Docker image or Dockerfile.
* This needs to be in the 'exec form', viz., `[ 'executable', 'param1', 'param2' ]`.
* @see https://docs.docker.com/engine/reference/builder/#cmd
* @default - use the CMD specified in the docker image or Dockerfile.
*/
readonly cmd?: string[];
/**
* Specify or override the ENTRYPOINT on the specified Docker image or Dockerfile.
* An ENTRYPOINT allows you to configure a container that will run as an executable.
* This needs to be in the 'exec form', viz., `[ 'executable', 'param1', 'param2' ]`.
* @see https://docs.docker.com/engine/reference/builder/#entrypoint
* @default - use the ENTRYPOINT in the docker image or Dockerfile.
*/
readonly entrypoint?: string[];
/**
* Specify or override the WORKDIR on the specified Docker image or Dockerfile.
* A WORKDIR allows you to configure the working directory the container will use.
* @see https://docs.docker.com/engine/reference/builder/#workdir
* @default - use the WORKDIR in the docker image or Dockerfile.
*/
readonly workingDirectory?: string;
} and update FunctionProps with: /**
* Specify or override Docker image asset properties for this specific function.
**/
readonly imageConfig: ImageConfig; Finally, we can update the CfnFunction call with: imageConfig: undefinedIfNoKeys({
command: props.imageConfig?.cmd || code.image?.cmd,
entryPoint: props.imageConfig?.entrypoint || code.image?.entrypoint,
workingDirectory: props.imageConfig?.workingDirectory || code.image?.workingDirectory,
}), |
Or would it be better to use the generated interface: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.CfnFunction.ImageConfigProperty.html ? |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
That's neat! I think the documentation could be improved then. It's not clear to me that multiple calls to |
Describe the feature
Add a
command
prop toDockerImageFunctionProps
to override the value specified in https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.AssetImageCodeProps.html#cmd .Use Case
I have a Docker image with multiple Lambda handlers. I would like to create the
DockerImageCode
once so it will build the image just once and then when creating eachDockerImageFunction
, I can specify the function to execute withcommand
.Proposed Solution
The synthesized CloudFormation for the AWS::Lambda::Function will include the value from the
command
prop asCommand
inImageConfig
. https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-imageconfig.html#cfn-lambda-function-imageconfig-commandOther Information
It is possible to override
CMD
from the dockerfile using https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda.AssetImageCodeProps.html#cmd , but that will result in multiple Docker images.Acknowledgements
CDK version used
2.143.0
Environment details (OS name and version, etc.)
MacOS 14.4.1 intel
The text was updated successfully, but these errors were encountered: