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-python] Automatic bundling not working correctly for aws_cdk.aws_lambda_python.PythonFunction when using the Python 3.8 runtime #9418

Closed
CarlosDomingues opened this issue Aug 3, 2020 · 3 comments
Assignees
Labels
@aws-cdk/aws-lambda-python bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@CarlosDomingues
Copy link

From the docs:

If requirements.txt exists at the entry path, the construct will handle installing all required modules in a Lambda compatible Docker container according to the runtime.

When not setting the runtime attribute or using aws_lambda.Runtime.PYTHON_3_7, the bundling works as expected. However, using aws_lambda.Runtime.PYTHON_3_8 fails.

Reproduction Steps

Create an aws_cdk.aws_lambda_python.PythonFunction object that uses the Python 3.8 runtime and needs an external dependency defined in requirements.txt:

<projetct_root>/app.py:

from aws_cdk import (
    core,
    aws_lambda,
    aws_lambda_python
)

from os import path

class AwsCdkStack(core.Stack):
    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        my_lambda = aws_lambda_python.PythonFunction(
            self,
            "mylambda",
            entry=path.join(".", "functions", "mylambda"),
            index="lambda-handler.py",
            handler="handler",
            runtime=aws_lambda.Runtime.PYTHON_3_8,
        )

default_env = core.Environment(account="<account>", region="<region>")

app = core.App()
AwsCdkStack(app, "my-app", env=default_env)
app.synth()

<projetct_root>/functions/mylambda/lambda-handler.py:

import requests as r

def handler(event, context):
     print(r.get("https://api.ipify.org?format=json").json())

<projetct_root>/functions/mylambda/requirements.txt:

requests==2.23.0

Error Log

During the bundling I can see several warnings such as:

WARNING: The directory '/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

Then finally it fails with the following error:

bash: rsync: command not found
....
jsii.errors.JSIIError: Failed to run bundling Docker image for asset my-app/mylambda/Code/Stage: Error: docker exited with status 127
Subprocess exited with error 1

Environment

  • CLI Version: 1.56.0 (build c1c174d)
  • Framework Version: 1.56.0
  • Node.js Version: v13.11.0
  • OS: Windows 10
  • Language (Version): Python (3.8.2)
@CarlosDomingues CarlosDomingues added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 3, 2020
@CarlosDomingues
Copy link
Author

CarlosDomingues commented Aug 3, 2020

I've made a quick test and it looks like a Docker image issue:

For amazon/aws-sam-cli-build-image-python3.7:latest:

$ docker run -it amazon/aws-sam-cli-build-image-python3.7:latest /bin/bash

bash-4.2# rsync --version
rsync  version 3.0.6  protocol version 30
Copyright (C) 1996-2009 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
    append, ACLs, xattrs, iconv, symtimes

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
are welcome to redistribute it under certain conditions.  See the GNU
General Public Licence for details.

For amazon/aws-sam-cli-build-image-python3.8:latest:

$ docker run -it amazon/aws-sam-cli-build-image-python3.8:latest /bin/bash
bash-4.2# rsync --version
bash: rsync: command not found

@adamdottv
Copy link
Contributor

Duplicate of #9349, fixed by #9355.

@eladb
Copy link
Contributor

eladb commented Aug 4, 2020

Closing as dup

@eladb eladb closed this as completed Aug 4, 2020
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-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

3 participants