Toggle navigation
Toggle navigation
This project
Loading...
Sign in
서승완
/
kappa
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
Jose Diaz-Gonzalez
2016-06-12 00:32:49 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4994192f02d01e3ed473d997801a32c10163e0a8
4994192f
1 parent
d5d6dc08
Convert readme to RST format
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
70 deletions
README.md → README.rst
setup.py
README.
md
→
README.
rst
View file @
4994192
=====
kappa
=====
[
![Build Status
](
https://travis-ci.org/garnaat/kappa.svg?branch=develop
)
](https://travis-ci.org/garnaat/kappa)
.. image:: https://travis-ci.org/garnaat/kappa.svg?branch=develop
:target: https://travis-ci.org/garnaat/kappa
[
![Code Health
](
https://landscape.io/github/garnaat/kappa/develop/landscape.svg
)
](https://landscape.io/github/garnaat/kappa/develop)
.. image:: https://landscape.io/github/garnaat/kappa/develop/landscape.svg
:target: https://landscape.io/github/garnaat/kappa/develop
**Kappa** is a command line tool that (hopefully) makes it easier to
deploy, update, and test functions for AWS Lambda.
...
...
@@ -12,10 +15,8 @@ There are quite a few steps involved in developing a Lambda function.
You have to:
* Write the function itself
*
Create the IAM role required by the Lambda function itself (the executing
role) to allow it access to any resources it needs to do its job
*
Add 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.
* Create the IAM role required by the Lambda function itself (the executing role) to allow it access to any resources it needs to do its job
* Add 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 Lambda
* Test the function with mock data
* Retrieve the output of the function from CloudWatch Logs
...
...
@@ -34,19 +35,19 @@ 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.
Installation
------------
============
The quickest way to get kappa is to install the latest stable version via pip:
The quickest way to get kappa is to install the latest stable version via pip:
:
pip install kappa
Or for the development version:
Or for the development version:
:
pip install git+https://github.com/garnaat/kappa.git
Quick Start
-----------
===========
To get a feel for how kappa works, let's take a look at a very simple example
contained in the ``samples/simple`` directory of the kappa distribution. This
...
...
@@ -54,38 +55,39 @@ 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:
The structure of the directory is:
:
```
simple/
├── _src
│ ├── README.md
│ ├── requirements.txt
│ ├── setup.cfg
│ └── simple.py
├── _tests
│ └── test_one.json
└── kappa.yml.sample
```
simple/
├── _src
│ ├── README.md
│ ├── requirements.txt
│ ├── setup.cfg
│ └── simple.py
├── _tests
│ └── test_one.json
└── kappa.yml.sample
Within the directory we see:
*
`
kappa.yml.sample
`
which is a sample YAML configuration file for the project
*
`
_src
`
which is a directory containing the source code for the Lambda function
*
`
_test
`
which is a directory containing some test data
* `
`kappa.yml.sample`
` which is a sample YAML configuration file for the project
* `
`_src`
` which is a directory containing the source code for the Lambda function
* `
`_test`
` which is a directory containing some test data
The first step is to make a copy of the sample configuration file:
$ cd simple
$ cp kappa.yml.sample kappa.yml
.. code-block:: bash
cd simple
cp kappa.yml.sample kappa.yml
Now you will need to edit ``kappa.yml`` slightly for your use. The file looks
like this:
```
---
name: kappa-simple
environments:
.. code-block:: yaml
---
name: kappa-simple
environments:
dev:
profile: <your profile here>
region: <your region here>
...
...
@@ -102,13 +104,12 @@ environments:
- arn: arn:aws:logs:*:*:*
actions:
- "*"
lambda:
lambda:
description: A very simple Kappa example
handler: simple.handler
runtime: python2.7
memory_size: 128
timeout: 3
```
The ``name`` at 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,
...
...
@@ -123,12 +124,14 @@ section also includes a ``policy`` section. 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
](
http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html
)
)
(
`Amazon Resource Name`_
)
that identify 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.
.. _`Amazon Resource Name`: http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html
The ``lambda`` section 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.
...
...
@@ -142,28 +145,27 @@ 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:
```
$ kappa deploy
```
.. code-block:: bash
kappa deploy
This assumes you want to deploy the default environment called ``dev`` and that
you have named your config file ``kappa.yml``. If, instead, you called your
environment ``test`` and named your config file foo.yml, you would do this:
```
$ kappa --env test --config foo.yml deploy
```
.. code-block:: bash
kappa --env test --config foo.yml deploy
In either case, you should see output that looks something like this:
```
$ kappa deploy
deploying
...deploying policy kappa-simple-dev
...creating function kappa-simple-dev
done
$
```
.. code-block:: bash
kappa deploy
# deploying
# ...deploying policy kappa-simple-dev
# ...creating function kappa-simple-dev
# done
So, what kappa has done is it has created a new Managed Policy called
``kappa-simple-dev`` that grants access to the CloudWatch Logs service. It has
...
...
@@ -173,19 +175,18 @@ Lambda called kappa-simple-dev.
To test this out, try this:
```
$ kappa invoke _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
.. code-block:: bash
Response:
{"status": "success"}
done
$
```
kappa invoke _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"}
# done
We have just called our Lambda function, passing in the contents of the file
``_tests/test_one.json`` as input to our function. We can see the output of
...
...
@@ -198,7 +199,9 @@ 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 the
``deploy`` command:
$ kappa deploy
.. code-block:: bash
kappa deploy
Kappa will figure out what has changed and make the necessary updates for you.
...
...
@@ -206,34 +209,34 @@ That gives you a quick overview of kappa. To learn more about it, I recommend
you check out the tutorial.
Policies
--------
========
Hands 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 your
`
kappa.yml
`
file, the
The simplified version allows you to specify, in your `
`kappa.yml`
` file, the
ARN of the resource you want to access, and then a list of the API methods you
want to allow. For example:
```
policy:
.. code-block:: yaml
policy:
resources:
- arn: arn:aws:logs:*:*:*
actions:
- "*"
```
To express this using the official IAM policy format, you can instead use a
statement:
```
policy:
.. code-block:: yaml
policy:
statements:
- Effect: Allow
Resource: "*"
Action:
- "logs:*"
```
Both of these do the same thing.
...
...
setup.py
View file @
4994192
...
...
@@ -16,7 +16,7 @@ setup(
name
=
'kappa'
,
version
=
open
(
os
.
path
.
join
(
'kappa'
,
'_version'
))
.
read
()
.
strip
(),
description
=
'A CLI tool for AWS Lambda developers'
,
long_description
=
open
(
'README.
md
'
)
.
read
(),
long_description
=
open
(
'README.
rst
'
)
.
read
(),
author
=
'Mitch Garnaat'
,
author_email
=
'mitch@garnaat.com'
,
url
=
'https://github.com/garnaat/kappa'
,
...
...
Please
register
or
login
to post a comment