Skip to content

Commit db5a81a

Browse files
adamchainzryansb
authored andcommitted
Convert README to reStructuredText
It's the only format [PyPI](https://pypi.python.org/pypi/cfn_resource/) supports, using markdown looks broken.
1 parent 9a2c9f8 commit db5a81a

4 files changed

Lines changed: 92 additions & 85 deletions

File tree

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Include the license file
22
include LICENSE.txt
3-
include README.md
3+
include README.rst

README.md

Lines changed: 0 additions & 83 deletions
This file was deleted.

README.rst

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
cfn\_resource.py
2+
----------------
3+
4+
This project is a decorator and validation system that takes the
5+
drudgery out of writing custom resources. You still have access to the
6+
context and event as normal, but the decorator handles serializing your
7+
response and communicating results to CloudFormation.
8+
9+
See `cfn-lambda <https://github.com/andrew-templeton/cfn-lambda>`__ from
10+
Andrew Templeton if you're looking to write your custom resources in
11+
Node.js.
12+
13+
Usage
14+
-----
15+
16+
1. Copy ``cfn_resource.py`` into the directory of your lambda function
17+
handler.py
18+
2. Use the ``cfn_resource.Resource`` event decorators to decorate your
19+
handler like in ``example.py``
20+
3. Zip up the contents and upload to Lambda
21+
22+
Once the function is up, copy its ARN and use it as the ServiceToken for
23+
your `custom
24+
resource <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cfn-customresource.html>`__.
25+
For more on the requests you may receive, see `this
26+
document <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-requests.html>`__
27+
28+
.. code-block:: json
29+
30+
{
31+
"AWSTemplateFormatVersion": "2010-09-09",
32+
"Resources": {
33+
"FakeThing": {
34+
"Type": "Custom::MyResource",
35+
"Properties": {
36+
"ServiceToken": "arn:aws:lambda:SOME-REGION:ACCOUNT:function:FunctionName",
37+
"OtherThing": "foobar",
38+
"AnotherThing": 2
39+
}
40+
}
41+
}
42+
}
43+
44+
For more on how custom resources work, see the `AWS
45+
docs <https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/template-custom-resources.html>`__
46+
47+
Code Sample
48+
-----------
49+
50+
For this example, you need to have your handler in Lambda set as
51+
``filename.handler`` where filename has the below contents.
52+
53+
.. code-block:: python
54+
55+
import cfn_resource
56+
57+
# set `handler` as the entry point for Lambda
58+
handler = cfn_resource.Resource()
59+
60+
@handler.create
61+
def create_thing(event, context):
62+
# do some stuff
63+
return {"PhysicalResourceId": "arn:aws:fake:myID"}
64+
65+
@handler.update
66+
def update_thing(event, context):
67+
# do some stuff
68+
return {"PhysicalResourceId": "arn:aws:fake:myID"}
69+
70+
Running Tests
71+
-------------
72+
73+
To run the tests locally, you need Python 2.7 and ``pip``. Ideally, you
74+
should use a virtualenv.
75+
76+
.. code-block:: sh
77+
78+
$ pip install -r test-requirements.txt
79+
$ py.test
80+
81+
The tests use ``mock`` and ``py.test`` and will give you a terminal
82+
coverage report. Currently the tests cover ~90% of the (very small)
83+
codebase.
84+
85+
License
86+
-------
87+
88+
This code is released under the MIT software license, see LICENSE.txt
89+
for details. No warranty of any kind is included, and the copyright
90+
notice must be included in redistributions.

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
test_deps = ['mock', 'pytest', 'pytest-cov', 'pytest-xdist']
1717

1818
# Get the long description from the README file
19-
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
19+
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
2020
long_description = f.read()
2121

2222
setup(

0 commit comments

Comments
 (0)