Skip to content
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

[aws-lambda] Lambda zip from DockerFile #9329

Closed
1 of 2 tasks
nakedible opened this issue Jul 29, 2020 · 1 comment · Fixed by #9728
Closed
1 of 2 tasks

[aws-lambda] Lambda zip from DockerFile #9329

nakedible opened this issue Jul 29, 2020 · 1 comment · Fixed by #9728
Assignees
Labels
@aws-cdk/aws-lambda Related to AWS Lambda effort/large Large work item – several weeks of effort feature-request A feature should be added or improved. in-progress This issue is being actively worked on. p2

Comments

@nakedible
Copy link

Currently CDK supports many ways to generate Lambda assets:

  • Lambda zip can be provided directly
  • Lambda zip can be created automatically from a directory or set of files
  • NodeJS functions can be bundled automatically by Parcel to create a zip
  • Custom bundler docker images can be provided

However, I think there is one obvious way that is missing: generating the Lambda zip by building a DockerFile. The code should simply build a Dockerfile, and then extract the /var/task directory from the built image and zip it for Lambda.

This would allow all the features of a Dockerfile to be used in a really simple manner - such as multi-stage builds, caching, etc.

Use Case

Building Lambda functions that utilize native code requires using Docker images to get the right libraries. It is hard to build a custom bundler for each usage when the desire is to simply be able to customize the build process inside the docker.

Proposed Solution

The calling code could be:

lambda.Code.fromDocker(path.join(__dirname, 'my-docker-lambda'))

Should have support for common Docker build things like build arguments, specifying the Dockerfile separately from the root directory, etc.

Simple example for Nodejs:

FROM amazon/aws-sam-cli-build-image-nodejs12.x
COPY package.json package-lock.json /var/task/
RUN npm ci
COPY . /var/task/

Simple example for Python:

FROM amazon/aws-sam-cli-build-image-python38
COPY requirements.txt /var/task/
RUN pip install -y -r requirements.txt
COPY . /var/task/

More complex example for Rust:

FROM amazon/aws-sam-cli-build-image-provided

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
 | sh -s -- -y --profile minimal --default-toolchain stable
RUN /root/.cargo/bin/rustup target add x86_64-unknown-linux-musl

WORKDIR /code
COPY Cargo.toml Cargo.lock ./

RUN set -x\
 && mkdir -p src\
 && echo "fn main() {println!(\"broken\")}" > src/main.rs\
 && /root/.cargo/bin/cargo build --release

COPY src/ src/
RUN set -x\
 && find target/release -type f -name code -exec touch -t 200001010000 {} +\
 && /root/.cargo/bin/cargo build --release

RUN cp /code/target/release/bootstrap /var/task/

Other

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@nakedible nakedible added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jul 29, 2020
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Jul 29, 2020
@ericzbeard ericzbeard assigned nija-at and unassigned ericzbeard Jul 30, 2020
@nija-at nija-at added effort/large Large work item – several weeks of effort p2 and removed needs-triage This issue or PR still needs to be triaged. labels Aug 4, 2020
@SomayaB SomayaB added the in-progress This issue is being actively worked on. label Aug 17, 2020
@mergify mergify bot closed this as completed in #9728 Oct 11, 2020
mergify bot pushed a commit that referenced this issue Oct 11, 2020
…lities (#9728)

This PR introduces `run()` and `cp()` utility methods to `BundlingDockerImage`. After building their own Docker images, users can more easily run the image or copy files out of the image to create their own assets without using the bundling mechanism.

Possibly closes #9329

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda effort/large Large work item – several weeks of effort feature-request A feature should be added or improved. in-progress This issue is being actively worked on. p2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants