A Command extension to setuptools that allows building an AWS Lamba dist and uploading to S3
Project description
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:
- 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)
- Effect: This will build (using bdist_wheel) and install your package, along with all of the dependencies in install_requires
- Usage:
- 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
- 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
- Effect: This will build (using ldist) and upload the resulting ZIP file to the specified S3 bucket
- Usage:
- 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.
- 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.
- Usage:
This extension also adds three new attributes to the setup() function:
- 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
- Usage:
- 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
- Usage:
- 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)
- Usage:
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!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file lambda-setuptools-0.6.0.tar.gz
.
File metadata
- Download URL: lambda-setuptools-0.6.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.1.0 requests-toolbelt/0.8.0 tqdm/4.61.2 CPython/2.7.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58fc2f743e9a625bcfb4e771b8d7d48bac7b273a863f4c14de26482393e9048c |
|
MD5 | b846620875f4e2242e575d14acff2f41 |
|
BLAKE2b-256 | 0d4e0b0a8041381ca2b54decccefb0c537966634af05c0a62ceaeb8746edc98e |
File details
Details for the file lambda_setuptools-0.6.0-py2.py3-none-any.whl
.
File metadata
- Download URL: lambda_setuptools-0.6.0-py2.py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.1.0 requests-toolbelt/0.8.0 tqdm/4.61.2 CPython/2.7.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4eb310160d74a789421386d300568ff3ea7fb26062c737c6a4a508b4e825f38a |
|
MD5 | 6fa10fbf3c68a0ab8decc7f34fff0329 |
|
BLAKE2b-256 | 611f1b6fb38c481e2f32033c3aa4079ed8d1ec7edf5bfc517ba6026498da9414 |