####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
- Effect: This will build (using bdist_wheel) and install your package, along with all of the dependencies in install_requires
- 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>
- Effect: This will build (using ldist) and upload the resulting ZIP file to the specified S3 bucket
- 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
- Effect: This will build (using ldist) and upload the resulting ZIP file to the specified S3 bucket
- Usage:
-
ldeploy
- Usage
ldeploy --swagger-path <swagger_spec_path> --deploy-stage <stage_name> --access-key=<my_access_key> --secret-access-key=<my_secret> --vpc-subnets=<SUBNET_IDS> --vpc-security-groups=<SECURITY_GROUP_IDS> --role=<AWS_ROLE> --region=<AWS_REGION>
- Effect: This will build (using ldist) and upload to AWS with the function name defined in
operationId
for each path and will map the lambda functions to each gateway if swagger-path is defined. If deploy-stage is defined, a new stage of that name will be created and the API will be deployed.- access-key Required only if default access key is not set. The access key to use to upload. If not provided, default access key set in environment variables will be use if set, otherwise will fail.
- secret-access-key Required only if default secret key is not set. The access key to use to upload. If not provided, default secret key set in environment variables will be use if set, otherwise will fail.
- swagger-path Optional. Path to swagger specification file (YAML or JSON). If not provided, api gateway will not be created.
- deploy-stage Optional. Name of the deployment stage when deploying API gateway
- vpc-subnets Optional. VPC Configuration list of subnet ids separated by a comma
- vpc-security-groups Optional. VPC Configuration list of security group ids separated by a comma
- role Required only when creating API gateway (i.e. if swagger-path is defined) AWS Gateway role to use when creating API gateway
- region Optional. AWS region to use. If not provided, default region set in environment variables will be use if set, otherwise will fail.
- Effect: This will build (using ldist) and upload to AWS with the function name defined in
- Usage
-
lambda_function
- Usage:
lambda_function=[<my_package>.<some_module>:<handler_name/swagger_path_operation_id>]
- 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 all your defined lambda handler function at the root-level
- Example:
- Usage:
lambda_function=[
"lambda_functions.aggregation_handler:aggregation",
"lambda_functions.polygon_handler:polygon",
"lambda_functions.distance_handler:distance"
]
- 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:
- lambda_config
- Usage:
lambda_config=<dict_lambda_configuration>
- Effect: This configuration will be used when creating the lambda functions on AWS and must adhere to boto3 configuration.
- Example:
- Usage:
lambda_config={
"Runtime": "python3.6",
"Timeout": 60,
"MemorySize": 128,
"Publish": True
}
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!