Giter VIP home page Giter VIP logo

lambda-setuptools's Introduction

lambda-setuptools

A Command extension to setuptools that builds an AWS Lambda compatible zip file and uploads it to an S3 bucket

Simply add setup_requires=['lambda_setuptools'] as an attribute to your setup.py file

This extension adds two new commands to setuptools:

  1. ldist
    • Usage: ldist --exclude-lambda-packages=<True | true | Yes | yes | False | false | No | no> --include-version=<True | true | Yes | yes | False | false | No | no> --build-layer=<True | true | Yes | yes | False | false | No | no> --layer-dir=<my_layer_dir>
      • Effect: This will build (using bdist_wheel) and install your package, along with all of the dependencies in install_requires
        • exclude-lambda-packages is optional. If not present it will default to True. If True, all packages provided by the AWS Lambda execution environment will be excluded from your lambda function package
        • include-version is optional. If not present it will default to True
        • build-layer is optional. If not present it will default to False. Set to True to build a layer instead of a function
        • layer-dir is optional. Defaults to python. Only used if build-layer is True
        • It is highly recommended that you DO NOT include boto3 or botocore in your install_requires dependencies as these are provided by the AWS Lambda environment. Include them at your own peril!
        • The result will be in dist/[your-package-name]-[version].zip (along with your wheel)
  2. lupload
    • Usage: lupload --access-key=<my_access_key> --secret-access-key=<my_secret> --s3-bucket=<my_S3_bucket> --kms-key-id=<my_KMS_key> --s3-prefix=<my_S3_key_prefix> --endpoint-url=<my_endpoint_url>
      • Effect: This will build (using ldist) and upload the resulting ZIP file to the specified S3 bucket
        • access-key ans secret-access-key are optional (and DEPRECATED). The new method of setting these is by using the boto3 standard (https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html). This allows for several methods of granting AWS access, including through the use of roles and assumed roles. If provided, these are set to AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables (respectively) in the local os.environ.
        • kms-key-id is optional. If it is not provided, standard AES256 encryption will be used
        • s3-prefix is optional. If it is not provided, the ZIP file will be uploaded to the root of the S3 bucket
        • endpoint_url is optional. If it is not provided, the default endpoint for the accessed account will be used
  3. lupdate
    • Usage: lupdate --function-names=<my_function1>,<my_function2>,<my_function3> --lambda-names=<my_name1>,<my_name2>,<my_name3> --layer-runtimes=python2.7,python3.6,python3.7 --region=<my_aws_region>
      • Effect: This will update the AWS Lambda function or layer code for the listed functions/layers. Functions/layers may be function names, partial ARNs (in the case of a function name) and/or full ARNs.
        • function-names is DEPRECATED. Use lambda-names instead. Joined as a set with lambda-names.
        • lambda-names contains the names of functions XOR layers, depending on the update type. Update type is sourced from ldist through lupload.
        • layer-runtimes is optional, and can be one or more of python2.7|python3.6|python3.7, seperated by commas. Defaults to all three.
        • Requires the use of lupload as the S3 object uploaded is used as the function/layer code to update.
        • region is optional. If it is not provided, then us-east-1 will be used.

This extension also adds three new attributes to the setup() function:

  1. lambda_function
    • Usage: lambda_function=<my_package>.<some_module>:<some_function>
    • Effect: ldist will create a root-level python module named <package_name>_function.py where package_name is derived from the name attribute. This created module will simply redefine your lambda handler function at the root-level
  2. lambda_module
    • Usage: lambda_module=<some_module>
    • Effect: ldist adds the named module to the list of py_modules to install, normally at the root level
  3. lambda_package
    • Usage: lambda_package=<some_dir>
    • Effect: ldist will copy the contents of the provided directory into the root level of the resulting lambda distribution. The provided directory MUST NOT have an __init__.py in it (e.g. - it can't be a real package)

All ldist attributes can be used in the same setup() call. It is up to the user to ensure that you don't step all over yourself...

Note that all other commands and attributes in setup.py will still work the way you expect them to.

Enjoy!

lambda-setuptools's People

Contributors

fxbonnet avatar jeffhung avatar joseph-wortmann avatar mikn avatar robin-norwood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lambda-setuptools's Issues

[Request] Expose AWS --endpoint-url parameter for lupload

First of all, thank you for creating this project!

Exposing --endpoint-url off of boto would be extremely useful for me, as I do local testing through AWS Localstack. As part of the CI/CD pipeline I'm building, it'd be nice if I was able to parameterize my call to lupload with the endpoint url of AWS Localstack, instead of my production AWS instance.

I'm not sure how to request a feature so I'm opening an issue, if there's a better way please let me know.

python setup.py lupdate not working - unrecognised options

When I try and update a lambda function using the below command:

python setup.py lupdate --function-names=<my-function-name> --s3-bucket=<my-bucket-name> --access-key=<my-access-key> --secret-access-key=<my-secret-key>

I get the following error:
error: option --s3-bucket not recognized

I'm guessing this is because the user_options on lupdate#LUpdate do not accept the s3-bucket, aws-access-key or secret-access-key options.

I'm happy to put a PR in that resolves this issue. Just wanted to make sure first that I wasn't causing the error myself by using incorrect syntax.

pypandoc missing in requires

Hi,

i am using your tool in a ci environment. I running into:

File "/tmp/easy_install-akkkxt1_/lambda-setuptools-0.1.7/setup.py", line 1, in <module>
   
ModuleNotFoundError: No module named 'pypandoc'

Apparently the setup_requires=['pypandoc'], is not daisy chained when I do a setup_requires=['lambda_setuptools']

Maybe it needs to be in install_requires?

cheers
w

Display error details when pip returns unsuccessfully

In ldist.py when the pip command fails (line 164) it only displays message "pip returned unsuccessfully"
It would be helpful when pip return code is not 0 to directly show the details. What about something like this:

stdout, stderr = pip.communicate()

if pip.returncode is not 0:
    log.info("pip stdout: {}".format(stdout))
    log.error("pip stderr: {}".format(stderr))
    raise DistutilsPlatformError('pip returned unsuccessfully')
else:
    log.debug("pip stdout: {}".format(stdout))
    log.debug("pip stderr: {}".format(stderr))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.