aws / aws/aws-cdk

aws_lambda: Allow for a script to generate Docker image

Open
#21,648 5 comments 0 reactions 0 assignees View on GitHub
@aws-cdk/aws-ecr-assets @aws-cdk/aws-lambda effort/medium feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the feature

Add an additional class method to `DockerImageCode` that allows a user to provide a script which produces the Docker image instead of the CDK executing Docker build itself.

### Use Case

I have a monorepo which uses Bazel and it is suboptimal to perform the entire build process of the Lambda image inside of the Dockerfile. Instead, I have Bazel produce the manifest of all of the files that need to be in the image and the Docker build simply copies these files into the image. Due to Bazel's sandboxing and use of symlinks, it is not possible to use the existing Bazel cache inside of a Docker image. As such, if I could use an external script, I would be able to use my existing setup that leverages the Bazel crash and get a much faster build time.

### Proposed Solution

Maybe something like this:

```
DockerImageCode.from_locally_generated_image(fn, *args, **kwargs)
```

where `fn` is in charge of creating the Docker image and returns its repository name/tag?

### Other Information

Right now, I am creating/uploading my images to ECR with external scripting to the CDK. Once something is deployed, it is not too bad, but the initial setup is error-prone.

### Acknowledgements

- [ ] I may be able to implement this feature request
- [ ] This feature might incur a breaking change

### CDK version used

latest

### Environment details (OS name and version, etc.)

Ubuntu 22.04

Contributor guide

Open the contributing guide

Research direction

Start by reading the DockerImageCode entry point and tracing how the existing Docker image build is executed. Define the external script contract, including how it creates and returns an image repository name/tag, then add coverage for successful and failing script-driven builds and verify the resulting Lambda image can be deployed.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, docker, typescript
Domain
build-system, cloud
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.