Skip to content

aws_lambda_python_alpha: BundlingOptions network parameter is ignored #34514

Open
@snovikov

Description

@snovikov

Describe the bug

While trying to create a Lambda Layer with python I have stumbled into network issue with Docker.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Library Version

No response

Expected Behavior

cdk synth should be successful.

Current Behavior

while running cdk synth:

$ cdk synth
...
#5 [2/2] RUN     python -m venv /usr/app/venv &&     mkdir /tmp/pip-cache &&     chmod -R 777 /tmp/pip-cache &&     pip install --upgrade pip &&     mkdir /tmp/poetry-cache &&     chmod -R 777 /tmp/poetry-cache &&     pip install pipenv==2022.4.8 poetry==1.5.1 &&     rm -rf /tmp/pip-cache/* /tmp/poetry-cache/*
#5 9.835 Requirement already satisfied: pip in /usr/app/venv/lib/python3.12/site-packages (24.3.1)
#5 29.86 WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7cd455a78800>: Failed to establish a new connection: [Errno -2] Name or service not known')': /simple/pip/
...
#5 285.5 ERROR: Could not find a version that satisfies the requirement pipenv==2022.4.8 (from versions: none)
#5 305.5 ERROR: No matching distribution found for pipenv==2022.4.8
#5 ERROR: process "/bin/sh -c python -m venv /usr/app/venv &&     mkdir /tmp/pip-cache &&     chmod -R 777 /tmp/pip-cache &&     pip install --upgrade pip &&     mkdir /tmp/poetry-cache &&     chmod -R 777 /tmp/poetry-cache &&     pip install pipenv==$PIPENV_VERSION poetry==$POETRY_VERSION &&     rm -rf /tmp/pip-cache/* /tmp/poetry-cache/*" did not complete successfully: exit code: 1
...
Dockerfile:22
--------------------
  21 |     
  22 | >>> RUN \
  23 | >>> # create a new virtualenv for python to use
  24 | >>> # so that it isn't using root
  25 | >>>     python -m venv /usr/app/venv && \
  26 | >>> # Create a new location for the pip cache
  27 | >>>     mkdir /tmp/pip-cache && \
  28 | >>> # Ensure all users can write to pip cache
  29 | >>>     chmod -R 777 /tmp/pip-cache && \
  30 | >>> # Upgrade pip (required by cryptography v3.4 and above, which is a dependency of poetry)
  31 | >>>     pip install --upgrade pip && \
  32 | >>> # Create a new location for the poetry cache
  33 | >>>     mkdir /tmp/poetry-cache && \
  34 | >>> # Ensure all users can write to poetry cache
  35 | >>>     chmod -R 777 /tmp/poetry-cache && \
  36 | >>> # Install pipenv and poetry
  37 | >>>     pip install pipenv==$PIPENV_VERSION poetry==$POETRY_VERSION && \
  38 | >>> # Ensure no temporary files remain in the caches
  39 | >>>     rm -rf /tmp/pip-cache/* /tmp/poetry-cache/*
  40 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c python -m venv /usr/app/venv &&     mkdir /tmp/pip-cache &&     chmod -R 777 /tmp/pip-cache &&     pip install --upgrade pip &&     mkdir /tmp/poetry-cache &&     chmod -R 777 /tmp/poetry-cache &&     pip install pipenv==$PIPENV_VERSION poetry==$POETRY_VERSION &&     rm -rf /tmp/pip-cache/* /tmp/poetry-cache/*" did not complete successfully: exit code: 1
jsii.errors.JavaScriptError: 
  Error: docker exited with status 1
  --> Command: docker build -t cdk-f8515da79edfce24e7a7b2abd249e3ed0eeeb071f8c15e42ebeabfa08cebc749 --platform "linux/amd64" --build-arg "IMAGE=public.ecr.aws/sam/build-python3.12" "/tmp/jsii-kernel-pAlGbN/node_modules/@aws-cdk/aws-lambda-python-alpha/lib"
      at dockerExec (/tmp/jsii-kernel-pAlGbN/node_modules/aws-cdk-lib/core/lib/private/asset-staging.js:2:237)
      at DockerImage.fromBuild (/tmp/jsii-kernel-pAlGbN/node_modules/aws-cdk-lib/core/lib/bundling.js:1:4761)
      at new Bundling (/tmp/jsii-kernel-pAlGbN/node_modules/@aws-cdk/aws-lambda-python-alpha/lib/bundling.js:40:50)
      at Bundling.bundle (/tmp/jsii-kernel-pAlGbN/node_modules/@aws-cdk/aws-lambda-python-alpha/lib/bundling.js:25:50)
      at new PythonLayerVersion (/tmp/jsii-kernel-pAlGbN/node_modules/@aws-cdk/aws-lambda-python-alpha/lib/layer.js:50:39)
      at new PythonLayerVersion (/tmp/jsii-kernel-pAlGbN/node_modules/aws-cdk-lib/core/lib/prop-injectable.js:1:488)
      at Kernel._Kernel_create (/tmp/tmpo7jy_gi8/lib/program.js:548:25)
      at Kernel.create (/tmp/tmpo7jy_gi8/lib/program.js:218:93)
      at KernelHost.processRequest (/tmp/tmpo7jy_gi8/lib/program.js:15467:36)
      at KernelHost.run (/tmp/tmpo7jy_gi8/lib/program.js:15427:22)

...
RuntimeError: docker exited with status 1
--> Command: docker build -t cdk-f8515da79edfce24e7a7b2abd249e3ed0eeeb071f8c15e42ebeabfa08cebc749 --platform "linux/amd64" --build-arg "IMAGE=public.ecr.aws/sam/build-python3.12" "/tmp/jsii-kernel-pAlGbN/node_modules/@aws-cdk/aws-lambda-python-alpha/lib"
Subprocess exited with error 1

Reproduction Steps

Example code:

from aws_cdk import (
    Stack,
    aws_lambda as _lambda,
    aws_lambda_python_alpha as lambda_python,
)
from constructs import Construct

class LambdaStack(Stack):
    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        # Lambda Layer from Python requirements
        layer = lambda_python.PythonLayerVersion(
            self, "LibLayer",
            entry="layer",
            compatible_runtimes=[_lambda.Runtime.PYTHON_3_12],
            bundling=lambda_python.BundlingOptions(
                network="host",
            ),
        )

The layer folder:

layer/
└── requirements.txt

The layer/requirements.txt

jwt==1.3.1
requests==2.32.3

Possible Solution

It seems, that network="host" parameter is ignored.

Additional Information/Context

No response

AWS CDK Library version (aws-cdk-lib)

2.196.0

AWS CDK CLI version

2.1004.0 (build f0ad96e)

Node.js Version

v20.19.2

OS

Ubuntu 24.04.2 LTS

Language

Python

Language Version

Python 3.12.3

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions