Package: kappa
Kappais a command line tool that (hopefully) makes it easier to
deploy, update, and test functions for AWS Lambda.There are quite a few steps involved in developing a Lambda function.
You have to:Write the function itselfCreate the IAM role required by the Lambda function itself (the executing role) to allow it access to any resources it needs to do its jobAdd additional permissions to the Lambda function if it is going to be used in a Push model (e.g. S3, SNS) rather than a Pull model.Zip the function and any dependencies and upload it to AWS LambdaTest the function with mock dataRetrieve the output of the function from CloudWatch LogsAdd an event source to the functionView the output of the live functionKappa tries to help you with some of this.  It creates all IAM policies for you
based on the resources you have told it you need to access.  It creates the IAM
execution role for you and associates the policy with it.  Kappa will zip up
the function and any dependencies and upload them to AWS Lambda.  It also sends
test data to the uploaded function and finds the related CloudWatch log stream
and displays the log events.  Finally, it will add the event source to turn
your function on.If you need to make changes, kappa will allow you to easily update your Lambda
function with new code or update your event sources as needed.InstallationThe quickest way to get kappa is to install the latest stable version via pip:pip install kappaOr for the development version:pip install git+https://github.com/garnaat/kappa.gitQuick StartTo get a feel for how kappa works, let’s take a look at a very simple example
contained in thesamples/simpledirectory of the kappa distribution.  This
example is so simple, in fact, that it doesn’t really do anything.  It’s just a
small Lambda function (written in Python) that accepts some JSON input, logs
that input to CloudWatch logs, and returns a JSON document back.The structure of the directory is:simple/
├── _src
│   ├── README.md
│   ├── requirements.txt
│   ├── setup.cfg
│   └── simple.py
├── _tests
│   └── test_one.json
└── kappa.yml.sampleWithin the directory we see:kappa.yml.samplewhich is a sample YAML configuration file for the project_srcwhich is a directory containing the source code for the Lambda function_testwhich is a directory containing some test dataThe first step is to make a copy of the sample configuration file:cdsimplecpkappa.yml.samplekappa.ymlNow you will need to editkappa.ymlslightly for your use.  The file looks
like this:---name:kappa-simpleenvironments:dev:profile:<your profile here>region:<your region here>environment_variables:<key 1>:<value 1><key 2>:<value 2>policy:resources:-arn:arn:aws:logs:*:*:*actions:-"*"prod:profile:<your profile here>region:<your region here>policy:resources:-arn:arn:aws:logs:*:*:*actions:-"*"lambda:description:A very simple Kappa examplehandler:simple.handlerruntime:python2.7memory_size:128timeout:3Thenameat the top is just a name used for this Lambda function and other
things we create that are related to this Lambda function (e.g. roles,
policies, etc.).Theenvironmentssection is where we define the different environments into
which we wish to deploy this Lambda function.  Each environment is identified
by aprofile(as used in the AWS CLI and other AWS tools) and aregion.  You can define as many environments as you wish but each
invocation ofkappawill deal with a single environment.  An environment
can optionally containenvironment variablesas key-value pairs.  Each
environment section also includes apolicysection.  This is where we tell
kappa about AWS resources that our Lambda function needs access to and what
kind of access it requires.  For example, your Lambda function may need to
read from an SNS topic or write to a DynamoDB table and this is where you would
provide the ARN (Amazon Resource Name) that identifies those resources.
Since this is a very simple example, the only resource listed here is for
CloudWatch logs so that our Lambda function is able to write to the CloudWatch
log group that will be created for it automatically by AWS Lambda.Thelambdasection contains the configuration information about our Lambda
function.  These values are passed to Lambda when we create the function and
can be updated at any time after.To modify this for your own use, you just need to put in the right values forprofileandregionin one of the environment sections.  You can also
change the names of the environments to be whatever you like but the namedevis the default value used by kappa so it’s kind of handy to avoid
typing.Once you have made the necessary modifications, you should be ready to deploy
your Lambda function to the AWS Lambda service.  To do so, just do this:kappadeployThis assumes you want to deploy the default environment calleddevand that
you have named your config filekappa.yml.  If, instead, you called your
environmenttestand named your config file foo.yml, you would do this:kappa--envtest--configfoo.ymldeployIn either case, you should see output that looks something like this:kappadeploy# deploying
# ...deploying policy kappa-simple-dev
# ...creating function kappa-simple-dev
# doneSo, what kappa has done is it has created a new Managed Policy calledkappa-simple-devthat grants access to the CloudWatch Logs service.  It has
also created an IAM role calledkappa-simple-devthat uses that policy.
And finally it has zipped up our Python code and created a function in AWS
Lambda called kappa-simple-dev.To test this out, try this:kappainvoke_tests/test_one.json# invoking
# START RequestId: 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f Version: $LATEST
# [DEBUG]   2015-12-08T22:00:15.363Z        0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f    {u'foo': u'bar', u'fie': u'baz'}
# END RequestId: 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f
# REPORT RequestId: 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f    Duration: 0.40 ms       Billed Duration: 100 ms         Memory Size: 256 MB     Max Memory Used: 23 MB
#
# Response:
# {"status": "success"}
# doneWe have just called our Lambda function, passing in the contents of the file_tests/test_one.jsonas input to our function.  We can see the output of
the CloudWatch logs for the call and we can see the logging call in the Python
function that prints out theevent(the data) passed to the function.  And
finally, we can see the Response from the function which, for now, is just a
hard-coded data structure returned by the function.Need to make a change in your function, your list of resources, or your
function configuration?  Just go ahead and make the change and then re-run thedeploycommand:kappadeployKappa will figure out what has changed and make the necessary updates for you.That gives you a quick overview of kappa.  To learn more about it, I recommend
you check out the tutorial.PoliciesHands up who loves writing IAM policies. Yeah, that’s what I thought. With
Kappa, there is a simplified way of writing policies and granting your Lambda
function the permissions it needs.The simplified version allows you to specify, in yourkappa.ymlfile, the
ARN of the resource you want to access, and then a list of the API methods you
want to allow. For example:policy:resources:-arn:arn:aws:logs:*:*:*actions:-"*"To express this using the official IAM policy format, you can instead use a
statement:policy:statements:-Effect:AllowResource:"*"Action:-"logs:*"Both of these do the same thing.