Package: pybuilder_aws_plugin
pybuilder_aws_pluginPyBuilder plugin to simplify building projects for Amazon Web Services. The
following use cases are supported:Packaging Python code forLambdaand uploading the result toS3.Maintain CloudFormation templates inYAMLand upload toS3. Conversion done
withcfn-sphere.Deploy code and templates for aCloudFormation custom resource backed by a
Lambda function.Incompatible Changes>161 (March 2016) Upload and Release are Separate StepsTill up to version 161upload_zip_to_s3andupload_cfn_to_s3tasks
would upload the files to S3 both under a versioned (v123) path and under alatestpath element. This behavior prevents testing the new version before
releasing it under thelatestpath.Since the task name “upload” does not imply “release” and since we believe inTest Driven Developmentwe decided to break backwards compatibility in this
case.From version 162 and onward the “upload” tasks will only upload files to S3
under a versioned path. We provide two new taskslambda_releaseandcfn_releaseto explicitly copy the files from the versioned path to thelatestpath.We apologize for the inconvenience and hope that this change will simplify your
integration tests.UsageAdd the following plugin dependency to yourbuild.py(will install directly
from PyPi):use_plugin('pypi:pybuilder_aws_plugin')After this you have the following additional tasks, which are explained below:package_lambda_codeupload_zip_to_s3upload_cfn_to_s3lambda_releasecfn_releaseupload_custom_resourcerelease_custom_resource@Task: package_lambda_codeThis taskassembles the Zip-file(a.k.a. thelambda-zip) which will be
uploaded toS3with the taskupload_zip_to_s3. This task consists of the
following steps:Add all dependenciesInstall every entry inbuild.py, that is specified by usingproject.depends_on(), into a temporary directory viapip install-t.
These will be included in the resulting lambda-zip. Set the project propertyinstall_dependencies_index_urlto use a custom index url (e.g. an internalPYPI server).Note:This excludesbotoandboto3as they are included inAWS lambda dependenciesby defaultAdd all own modulesAll modules which are found insrc/main/python/are copied directly into
the lambda-zip.Add all script filesThe content of the scripts folder (src/main/scripts) in a PyBuilder project
is normally intended to be placed in/usr/bin. This plugin assumes this
directory contains scripts including the lambda handler functions. Therefore
all files under this folder are copied directly to the root directory (/)
of the lambda-zip.Pack everything into the Zip-fileAll these files are packed as a Zip-file that complies with theLambdaspecification.@Task: upload_zip_to_s3This task uploads the generated zip to anS3bucket. The bucket name is set inbuild.py:project.set_property('bucket_name','my_lambda_bucket')The default acl for zips to be uploaded isbucket-owner-full-control. But
if you need another acl you can overwrite this as follows inbuild.py:project.set_property('lambda_file_access_control','<acl>')Possible acl values are:privatepublic-readpublic-read-writeauthenticated-readbucket-owner-readbucket-owner-full-controlFurthermore, the plugin assumes that you already have a shell with enabled AWS
access (exported keys or .boto or …).afp-cliis a tool to provide temporary
credentials for shell users.The uploaded files will be placed in a directory with the version number like:v123/projectname.zip.Use the propertybucket_prefixto add a prefix to the uploaded
files. For example:project.set_property('bucket_prefix','my_lambda/')This will upload the zip-file to the following key:my_lambda/v123/projectname.zipOnTeamCityyou can enable setting a TeamCity build parameter with the key of
the uploaded zip-file:After uploading the zip-file toS3the plugin will emit a##teamcity[setParameter name='my_tc_parameter' value='my_lambda/v123/project-name.zip']line which TeamCity can parse. You can then use the value in other build steps.@Task: upload_cfn_to_s3NOTE: This task is available for Python 2.7 and up, due tocfn-spheredependencies not being available for Python 2.6.This task converts and uploads the CFN-Sphere templateYAMLfiles asJSONto
aS3bucket.  Set the bucket name inbuild.py:project.set_property('bucket_name','my_template_bucket')Define the CFN templates to upload via a list of
tuples in thetemplate_filesproperty:project.set_property('template_files',[('path1','filename1.yaml'),('path2','filename2.yaml'),...])The uploaded files will be placed in a directory with the version number:v123/filename1.jsonv123/filename2.jsonUse the propertytemplate_key_prefixto add a prefix to the uploaded
files. For example:project.set_property('template_key_prefix','my_template/')This will upload the files to the following files:my_template/v123/filename1.jsonmy_template/v123/filename2.jsonThe ACL for theJSONfiles isbucket-owner-full-control. Set another ACL
inbuild.py:project.set_property('template_file_access_control','<acl>')Possible acl values are:privatepublic-readpublic-read-writeauthenticated-readbucket-owner-readbucket-owner-full-control@Task: lambda_release, cfn_releaseThese tasks copy the lambda-zip or CFN template files from the versioned path
to version independant path namedlatest. For Example:my_lambda/v123/my-project.zipis copied tomy_lambda/latest/my-project.zipmy_templates/v123/my-cfn.jsonis copied tomy_templates/latest/my-cfn.jsonThis provides a simple release mechanism that follows the “latest greatest”
principle. Users can rely on the files underlatestto be the latest tested
version.@Task: upload_custom_resource, release_custom_resourceFor CloudFormation custom resources backed by a Lambda function these two tasks
provide convenience wrappers to implement an “Update - Test - Release” process:#!/bin/bashset-epybupload_custom_resource./run-integration-test.pypybrelease_custom_resourceTheupload_custom_resourcetask bundles theupload_zip_to_s3and theupload_cfn_to_s3task. It is strongly recmomended tonotuse abucket_prefixin order to keep the lambda-zip and CFN templates in the same
direcory on S3.LicenceCopyright 2015,2016 Immobilien Scout GmbHLicensed under the Apache License, Version 2.0 (the “License”); you may not use
this file except in compliance with the License. You may obtain a copy of the
License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.