Package: possum
Python AWS SAM–>PyAWSSAM–>Pawssam–>PossumInstallPossum can be installed from the Python Package Index:$ pip install possumPossum requiresPython 3.6+andpipenv(pipenvmust be installed
separately and is not installed with Possum).AboutPossum is a packaging tool for serverless Python-based applications
using the AWS Serverless Application Model (AWS SAM).Thesam packageoraws cloudformation packageoptions have a
limitation when it comes to Python Lambda functions: they have no means
of packaging external dependencies. This means that developers are
always on their own for creating those Lambda artifacts, uploading them
to S3, and deploying.Possum aims to serve as a replacement to the basic package functions.
The tool is based upon my approach to serverless AWS applications
(opinionated) and may not be a fit for all parties.AWS CredentialsPossum uses the Boto3 SDK for uploading artifacts to S3. You can set your
AWS access and secret keys in your environment variables as described in
the Boto3 documentation. Possom also accept a profile name for your AWS
credentials file via the-p/--profileargument.$ possum '<s3-bucket-name>' --profile '<my-profile-name>'Basic UsageRun Possum from the repository directory containing the serverless
application.$ possum '<s3-bucket-name>'The above command will package the Python Lambda functions and upload
them to S3 assuming the template file is namedtemplate.yaml. You
can specify the template’s name with the-t/--templateargument:$ possum '<s3-bucket-name>' -t my-template.ymlThe generated deployment template will printed on the screen.By default, Possum will uploadnewartifacts to a directory in your chosen S3
bucket namedpossum-0123456789where the numerical value is the current
timestamp.If you wish to override this default and specify the directory path to upload
new artifact, append it to the S3 bucket name using forward slashes:$ possum '<s3-bucket-name>/<my_path>'You can also specify the deployment template be written to a file by
passing a name to the-o/--output-templateargument:$ possum '<s3-bucket-name>' -o deployment.yamlPossum uses hashes of your function directories to determine if changes have
occurred since the last run of the command. Hashes and S3 URIs are saved in a~/.possumdirectory for each project you package with Possum.To force Possum to build all functions and skip the hash check, use the-c/--cleanargument.You can view the options and instructions for using Possum with the-hargument:$ possum -h
usage: possum [-h] [-t template] [-o output] [-p profile_name] [-c] [--docker]
          [--docker-image image_name] [-v]
          s3_bucket

Possum is a utility to package Python-based serverless applications using the
Amazon Serverless Application model with per-function dependencies.

positional arguments:
  s3_bucket             The S3 bucket to upload artifacts. You may optionally
                        pass a path within the bucket to store the Lambda
                        artifacts (defaults to 'possum-{timestamp}').

optional arguments:
  -h, --help            show this help message and exit
  -t template, --template template
                        The filename of the SAM template.
  -o output, --output-template output
                        Optional filename for the output template.
  -p profile_name, --profile profile_name
                        Optional profile name for AWS credentials.
  -c, --clean           Build all Lambda packages, ignoring previous run.
  --docker              Build Lambda packages within a Docker container
                        environment.
  --docker-image image_name
                        Specify a Docker image to use (defaults to
                        'possum:latest').
  -v, --version         Display version information.Docker SupportThe installation of some Python packages differ based on the underlying system
(cryptography.io is an example). To ensure your installed dependencies are
fully compatible with the Lambda environment, you may opt to run Possum within
a Docker container.The includedDockerfilein this project will create a compatible default
image to use. Run the following command from the same directory as theDockerfileto build the image:$ docker build . -t possum:latestThis image is based uponlambci/lambda:build-python3.6. You may build your
own custom image and specify it using the--docker-imageargument. If you
decide to use your own image it must havepipenvandpossuminstalled!Launch Possum in a container using the--dockerargument:$ possum '<s3-bucket-name>' --dockerServerless App Repository ExampleHere is an example of a serverless Python application with multiple Lambda
functions in a single repository:my_prjoect/
    |
    |___template.yaml
    |
    |___function1/
    |   |
    |   |___function1.py
    |
    |___function2/
        |
        |___function2.py
        |___Pipfile
        |___Pipfile.lockFor each AWS Lambda function defined in the template, Possum references
theProperties:CodeUrikey for the path to the function’s directory.Possum will display a warning if the function’sProperties:Runtimevalue does not matchpython*. You will need to package these remaining
functions separately.The contents of each functions’ directory will be copied to a temporary
build directory. If aPipfile/Pipfile.lockorrequirements.txtexist, the external packages will be installed into the build directory. The
entire contents of the build directory will then be zipped into a deployable
Lambda artifact.All artifacts will be uploaded to the provided S3 bucket. The imported
template will be updated with the S3 locations for each Lambda function
and writtenstdoutor a file if the-oargument was provided.The generated deployment template can be used withsam deployoraws cloudformation deployto deploy the application.