Jose Diaz-Gonzalez

Convert readme to RST format

1 +=====
1 kappa 2 kappa
2 ===== 3 =====
3 4
4 -[![Build Status](https://travis-ci.org/garnaat/kappa.svg?branch=develop)](https://travis-ci.org/garnaat/kappa) 5 +.. image:: https://travis-ci.org/garnaat/kappa.svg?branch=develop
6 + :target: https://travis-ci.org/garnaat/kappa
5 7
6 -[![Code Health](https://landscape.io/github/garnaat/kappa/develop/landscape.svg)](https://landscape.io/github/garnaat/kappa/develop) 8 +.. image:: https://landscape.io/github/garnaat/kappa/develop/landscape.svg
9 + :target: https://landscape.io/github/garnaat/kappa/develop
7 10
8 **Kappa** is a command line tool that (hopefully) makes it easier to 11 **Kappa** is a command line tool that (hopefully) makes it easier to
9 deploy, update, and test functions for AWS Lambda. 12 deploy, update, and test functions for AWS Lambda.
...@@ -12,10 +15,8 @@ There are quite a few steps involved in developing a Lambda function. ...@@ -12,10 +15,8 @@ There are quite a few steps involved in developing a Lambda function.
12 You have to: 15 You have to:
13 16
14 * Write the function itself 17 * Write the function itself
15 -* Create the IAM role required by the Lambda function itself (the executing 18 +* 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
16 -role) to allow it access to any resources it needs to do its job 19 +* 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.
17 -* Add additional permissions to the Lambda function if it is going to be used
18 -in a Push model (e.g. S3, SNS) rather than a Pull model.
19 * Zip the function and any dependencies and upload it to AWS Lambda 20 * Zip the function and any dependencies and upload it to AWS Lambda
20 * Test the function with mock data 21 * Test the function with mock data
21 * Retrieve the output of the function from CloudWatch Logs 22 * 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 ...@@ -34,19 +35,19 @@ If you need to make changes, kappa will allow you to easily update your Lambda
34 function with new code or update your event sources as needed. 35 function with new code or update your event sources as needed.
35 36
36 Installation 37 Installation
37 ------------- 38 +============
38 39
39 -The quickest way to get kappa is to install the latest stable version via pip: 40 +The quickest way to get kappa is to install the latest stable version via pip::
40 41
41 pip install kappa 42 pip install kappa
42 43
43 -Or for the development version: 44 +Or for the development version::
44 45
45 pip install git+https://github.com/garnaat/kappa.git 46 pip install git+https://github.com/garnaat/kappa.git
46 47
47 48
48 Quick Start 49 Quick Start
49 ------------ 50 +===========
50 51
51 To get a feel for how kappa works, let's take a look at a very simple example 52 To get a feel for how kappa works, let's take a look at a very simple example
52 contained in the ``samples/simple`` directory of the kappa distribution. This 53 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 ...@@ -54,38 +55,39 @@ example is so simple, in fact, that it doesn't really do anything. It's just a
54 small Lambda function (written in Python) that accepts some JSON input, logs 55 small Lambda function (written in Python) that accepts some JSON input, logs
55 that input to CloudWatch logs, and returns a JSON document back. 56 that input to CloudWatch logs, and returns a JSON document back.
56 57
57 -The structure of the directory is: 58 +The structure of the directory is::
58 59
59 -``` 60 + simple/
60 -simple/ 61 + ├── _src
61 -├── _src 62 + │   ├── README.md
62 -│   ├── README.md 63 + │   ├── requirements.txt
63 -│   ├── requirements.txt 64 + │   ├── setup.cfg
64 -│   ├── setup.cfg 65 + │   └── simple.py
65 -│   └── simple.py 66 + ├── _tests
66 -├── _tests 67 + │   └── test_one.json
67 -│   └── test_one.json 68 + └── kappa.yml.sample
68 -└── kappa.yml.sample
69 -```
70 69
71 Within the directory we see: 70 Within the directory we see:
72 71
73 -* `kappa.yml.sample` which is a sample YAML configuration file for the project 72 +* ``kappa.yml.sample`` which is a sample YAML configuration file for the project
74 -* `_src` which is a directory containing the source code for the Lambda function 73 +* ``_src`` which is a directory containing the source code for the Lambda function
75 -* `_test` which is a directory containing some test data 74 +* ``_test`` which is a directory containing some test data
76 75
77 The first step is to make a copy of the sample configuration file: 76 The first step is to make a copy of the sample configuration file:
78 77
79 - $ cd simple 78 +.. code-block:: bash
80 - $ cp kappa.yml.sample kappa.yml 79 +
80 + cd simple
81 + cp kappa.yml.sample kappa.yml
81 82
82 Now you will need to edit ``kappa.yml`` slightly for your use. The file looks 83 Now you will need to edit ``kappa.yml`` slightly for your use. The file looks
83 like this: 84 like this:
84 85
85 -``` 86 +.. code-block:: yaml
86 ---- 87 +
87 -name: kappa-simple 88 + ---
88 -environments: 89 + name: kappa-simple
90 + environments:
89 dev: 91 dev:
90 profile: <your profile here> 92 profile: <your profile here>
91 region: <your region here> 93 region: <your region here>
...@@ -102,13 +104,12 @@ environments: ...@@ -102,13 +104,12 @@ environments:
102 - arn: arn:aws:logs:*:*:* 104 - arn: arn:aws:logs:*:*:*
103 actions: 105 actions:
104 - "*" 106 - "*"
105 -lambda: 107 + lambda:
106 description: A very simple Kappa example 108 description: A very simple Kappa example
107 handler: simple.handler 109 handler: simple.handler
108 runtime: python2.7 110 runtime: python2.7
109 memory_size: 128 111 memory_size: 128
110 timeout: 3 112 timeout: 3
111 -```
112 113
113 The ``name`` at the top is just a name used for this Lambda function and other 114 The ``name`` at the top is just a name used for this Lambda function and other
114 things we create that are related to this Lambda function (e.g. roles, 115 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 ...@@ -123,12 +124,14 @@ section also includes a ``policy`` section. This is where we tell kappa about
123 AWS resources that our Lambda function needs access to and what kind of access 124 AWS resources that our Lambda function needs access to and what kind of access
124 it requires. For example, your Lambda function may need to read from an SNS 125 it requires. For example, your Lambda function may need to read from an SNS
125 topic or write to a DynamoDB table and this is where you would provide the ARN 126 topic or write to a DynamoDB table and this is where you would provide the ARN
126 -([Amazon Resource Name](http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html)) 127 +(`Amazon Resource Name`_)
127 that identify those resources. Since this is a very simple example, the only 128 that identify those resources. Since this is a very simple example, the only
128 resource listed here is for CloudWatch logs so that our Lambda function is able 129 resource listed here is for CloudWatch logs so that our Lambda function is able
129 to write to the CloudWatch log group that will be created for it automatically 130 to write to the CloudWatch log group that will be created for it automatically
130 by AWS Lambda. 131 by AWS Lambda.
131 132
133 +.. _`Amazon Resource Name`: http://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html
134 +
132 The ``lambda`` section contains the configuration information about our Lambda 135 The ``lambda`` section contains the configuration information about our Lambda
133 function. These values are passed to Lambda when we create the function and 136 function. These values are passed to Lambda when we create the function and
134 can be updated at any time after. 137 can be updated at any time after.
...@@ -142,28 +145,27 @@ typing. ...@@ -142,28 +145,27 @@ typing.
142 Once you have made the necessary modifications, you should be ready to deploy 145 Once you have made the necessary modifications, you should be ready to deploy
143 your Lambda function to the AWS Lambda service. To do so, just do this: 146 your Lambda function to the AWS Lambda service. To do so, just do this:
144 147
145 -``` 148 +.. code-block:: bash
146 -$ kappa deploy 149 +
147 -``` 150 + kappa deploy
148 151
149 This assumes you want to deploy the default environment called ``dev`` and that 152 This assumes you want to deploy the default environment called ``dev`` and that
150 you have named your config file ``kappa.yml``. If, instead, you called your 153 you have named your config file ``kappa.yml``. If, instead, you called your
151 environment ``test`` and named your config file foo.yml, you would do this: 154 environment ``test`` and named your config file foo.yml, you would do this:
152 155
153 -``` 156 +.. code-block:: bash
154 -$ kappa --env test --config foo.yml deploy 157 +
155 -``` 158 + kappa --env test --config foo.yml deploy
156 159
157 In either case, you should see output that looks something like this: 160 In either case, you should see output that looks something like this:
158 161
159 -``` 162 +.. code-block:: bash
160 -$ kappa deploy 163 +
161 -deploying 164 + kappa deploy
162 -...deploying policy kappa-simple-dev 165 + # deploying
163 -...creating function kappa-simple-dev 166 + # ...deploying policy kappa-simple-dev
164 -done 167 + # ...creating function kappa-simple-dev
165 -$ 168 + # done
166 -```
167 169
168 So, what kappa has done is it has created a new Managed Policy called 170 So, what kappa has done is it has created a new Managed Policy called
169 ``kappa-simple-dev`` that grants access to the CloudWatch Logs service. It has 171 ``kappa-simple-dev`` that grants access to the CloudWatch Logs service. It has
...@@ -173,19 +175,18 @@ Lambda called kappa-simple-dev. ...@@ -173,19 +175,18 @@ Lambda called kappa-simple-dev.
173 175
174 To test this out, try this: 176 To test this out, try this:
175 177
176 -``` 178 +.. code-block:: bash
177 -$ kappa invoke _tests/test_one.json
178 -invoking
179 -START RequestId: 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f Version: $LATEST
180 -[DEBUG] 2015-12-08T22:00:15.363Z 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f {u'foo': u'bar', u'fie': u'baz'}
181 -END RequestId: 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f
182 -REPORT RequestId: 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f Duration: 0.40 ms Billed Duration: 100 ms Memory Size: 256 MB Max Memory Used: 23 MB
183 179
184 -Response: 180 + kappa invoke _tests/test_one.json
185 -{"status": "success"} 181 + # invoking
186 -done 182 + # START RequestId: 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f Version: $LATEST
187 -$ 183 + # [DEBUG] 2015-12-08T22:00:15.363Z 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f {u'foo': u'bar', u'fie': u'baz'}
188 -``` 184 + # END RequestId: 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f
185 + # REPORT RequestId: 0f2f9ecf-9df7-11e5-ae87-858fbfb8e85f Duration: 0.40 ms Billed Duration: 100 ms Memory Size: 256 MB Max Memory Used: 23 MB
186 + #
187 + # Response:
188 + # {"status": "success"}
189 + # done
189 190
190 We have just called our Lambda function, passing in the contents of the file 191 We have just called our Lambda function, passing in the contents of the file
191 ``_tests/test_one.json`` as input to our function. We can see the output of 192 ``_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 ...@@ -198,7 +199,9 @@ Need to make a change in your function, your list of resources, or your
198 function configuration? Just go ahead and make the change and then re-run the 199 function configuration? Just go ahead and make the change and then re-run the
199 ``deploy`` command: 200 ``deploy`` command:
200 201
201 - $ kappa deploy 202 +.. code-block:: bash
203 +
204 + kappa deploy
202 205
203 Kappa will figure out what has changed and make the necessary updates for you. 206 Kappa will figure out what has changed and make the necessary updates for you.
204 207
...@@ -206,34 +209,34 @@ That gives you a quick overview of kappa. To learn more about it, I recommend ...@@ -206,34 +209,34 @@ That gives you a quick overview of kappa. To learn more about it, I recommend
206 you check out the tutorial. 209 you check out the tutorial.
207 210
208 Policies 211 Policies
209 --------- 212 +========
210 213
211 Hands up who loves writing IAM policies. Yeah, that's what I thought. With 214 Hands up who loves writing IAM policies. Yeah, that's what I thought. With
212 Kappa, there is a simplified way of writing policies and granting your Lambda 215 Kappa, there is a simplified way of writing policies and granting your Lambda
213 function the permissions it needs. 216 function the permissions it needs.
214 217
215 -The simplified version allows you to specify, in your `kappa.yml` file, the 218 +The simplified version allows you to specify, in your ``kappa.yml`` file, the
216 ARN of the resource you want to access, and then a list of the API methods you 219 ARN of the resource you want to access, and then a list of the API methods you
217 want to allow. For example: 220 want to allow. For example:
218 221
219 -``` 222 +.. code-block:: yaml
220 -policy: 223 +
224 + policy:
221 resources: 225 resources:
222 - arn: arn:aws:logs:*:*:* 226 - arn: arn:aws:logs:*:*:*
223 actions: 227 actions:
224 - "*" 228 - "*"
225 -```
226 229
227 To express this using the official IAM policy format, you can instead use a 230 To express this using the official IAM policy format, you can instead use a
228 statement: 231 statement:
229 232
230 -``` 233 +.. code-block:: yaml
231 -policy: 234 +
235 + policy:
232 statements: 236 statements:
233 - Effect: Allow 237 - Effect: Allow
234 Resource: "*" 238 Resource: "*"
235 Action: 239 Action:
236 - "logs:*" 240 - "logs:*"
237 -```
238 241
239 Both of these do the same thing. 242 Both of these do the same thing.
......
...@@ -16,7 +16,7 @@ setup( ...@@ -16,7 +16,7 @@ setup(
16 name='kappa', 16 name='kappa',
17 version=open(os.path.join('kappa', '_version')).read().strip(), 17 version=open(os.path.join('kappa', '_version')).read().strip(),
18 description='A CLI tool for AWS Lambda developers', 18 description='A CLI tool for AWS Lambda developers',
19 - long_description=open('README.md').read(), 19 + long_description=open('README.rst').read(),
20 author='Mitch Garnaat', 20 author='Mitch Garnaat',
21 author_email='mitch@garnaat.com', 21 author_email='mitch@garnaat.com',
22 url='https://github.com/garnaat/kappa', 22 url='https://github.com/garnaat/kappa',
......