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_cdk.aws_lambda_python_alpha: Enforced 'image' argument when using bundling in PythonLayerVersion #24859

Closed
garysassano opened this issue Mar 29, 2023 · 3 comments
Labels
@aws-cdk/aws-lambda-python bug This issue is a bug. needs-reproduction This issue needs reproduction. p2

Comments

@garysassano
Copy link

garysassano commented Mar 29, 2023

Describe the bug

According to the documentation present HERE, the following code should work, since in no place it is said that image is a mandatory argument of bundling.

lambda_layer = _alambda.PythonLayerVersion(
    self,
    "LambdaLayer_test-layer",
    layer_version_name="test-layer",
    entry=path,
    compatible_runtimes=[_lambda.Runtime.PYTHON_3_9],
    removal_policy=RemovalPolicy.DESTROY,
    bundling=BundlingOptions(
        environment={"PIP_INDEX_URL": codeartifact_index_url},
    ),
)

But to fix the error you need to add an image argument so the code becomes like this:

image = DockerImage.from_registry("amazon/aws-sam-cli-build-image-python3.9")
lambda_layer = _alambda.PythonLayerVersion(
    self,
    "LambdaLayer_test-layer",
    layer_version_name="test-layer",
    entry=path,
    compatible_runtimes=[_lambda.Runtime.PYTHON_3_9],
    removal_policy=RemovalPolicy.DESTROY,
    bundling=_alambda.BundlingOptions(
        image=image,
        environment={"PIP_INDEX_URL": codeartifact_index_url},
    ),
)

Expected Behavior

I think the code should work without the need to provide an image argument. If you can create a PythonLayerVersion using the public PyPI by just specifying your Python packages in a requirements.txt file that you provide as entry argument, then why it cannot be the same for an AWS CodeArtifact private PyPI? I honestly don't get it.

Current Behavior

TypeError: __init__() missing 1 required keyword-only argument: 'image'

Reproduction Steps

See snippets provided in bug description.

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.70.0

Framework Version

No response

Node.js Version

19.4.0

OS

Windows 11 22H2

Language

Python

Language Version

Python 3.9

Other information

No response

@garysassano garysassano added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 29, 2023
@garysassano garysassano changed the title aws_cdk.aws_lambda_python_alpha : Enforced 'image' argument when using bundling in PythonLayerVersion aws_cdk.aws_lambda_python_alpha: Enforced 'image' argument when using bundling in PythonLayerVersion Mar 29, 2023
@pahud pahud self-assigned this Mar 30, 2023
@pahud
Copy link
Contributor

pahud commented Mar 30, 2023

Unfortunately I can't reproduce this error.

My code:

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

class IssueTriagePyStack(Stack):

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

        lambda_layer = _alambda.PythonLayerVersion(
            self,
            "LambdaLayer_test-layer",
            layer_version_name="test-layer",
            entry='./assets.d',
            compatible_runtimes=[_lambda.Runtime.PYTHON_3_9],
            removal_policy=RemovalPolicy.DESTROY,
            bundling=_alambda.BundlingOptions(
                environment={"PIP_INDEX_URL": "dummyURL"},
            ),
        )

I am using CDK 2.70.0.

I am leaving this issue open as p2 and we probably need more report before we can address this issue.

@pahud pahud added p2 needs-reproduction This issue needs reproduction. labels Mar 30, 2023
@pahud pahud removed their assignment Mar 30, 2023
@pahud pahud removed the needs-triage This issue or PR still needs to be triaged. label Mar 30, 2023
@Leo10Gama
Copy link
Member

Unfortunately I am also unable to reproduce this error with the following code:

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

class IssueEnforceImageStack(Stack):

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

        lambda_layer = _alambda.PythonLayerVersion(
            self,
            "LambdaLayer_test-layer",
            layer_version_name="test-layer",
            entry='./lambda',
            compatible_runtimes=[_lambda.Runtime.PYTHON_3_9],
            removal_policy=RemovalPolicy.DESTROY,
            bundling=_alambda.BundlingOptions(
                environment={"PIP_INDEX_URL": "https://pypi.org/simple"},
            ),
        )

I am using CDK 2.140.0.

Since this issue has been open for almost a year now without further comment, and is not able to be reproduced with the information given, I am closing it. If the issue persists, please feel free to open a new issue.

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-python bug This issue is a bug. needs-reproduction This issue needs reproduction. p2
Projects
None yet
Development

No branches or pull requests

3 participants