You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.rst
+17-20Lines changed: 17 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,38 +34,33 @@ Requirements
34
34
* Virtualenv (~15.0.0)
35
35
* Virtualenvwrapper (~4.7.1)
36
36
37
-
Installation
38
-
============
37
+
Getting Started
38
+
===============
39
39
40
-
Create a new folder for your project and create a virtualenv.
40
+
Begin by creating a new virtualenv and project folder.
41
41
42
42
.. code:: bash
43
43
44
-
$ mkdir my_microservice
45
44
$ mkvirtualenv my_microservice
45
+
(my_microservice) $ mkdir my_microservice
46
46
47
-
Next Download using pip via pypi.
47
+
Next, download *Python-Lambda* using pip via pypi.
48
48
49
49
.. code:: bash
50
50
51
51
(my_microservice) $ pip install python-lambda
52
52
53
-
Getting Started
54
-
===============
55
-
56
-
The following will walk you through writing your first microservice with *Python-lambda*.
57
-
58
53
From your ``my_microservice`` directory, run the following to bootstrap your project.
59
54
60
55
.. code:: bash
61
56
62
57
(my_microservice) $ lambda init
63
58
64
-
If you look at the directory you will see four files were created: ``event.json``, ``__init__.py``, ``service.py``, and ``config.yaml``.
59
+
This will create the following files: ``event.json``, ``__init__.py``, ``service.py``, and ``config.yaml``.
65
60
66
-
Let's begin by taking a look at ``config.yaml`` in your favorite text editor. For the purpose of this tutorial, the only thing required to be entered is ``aws_access_key_id`` and ``aws_secret_access_key``. You can find these by logging into the AWS management console.
61
+
Let's begin by opening ``config.yaml`` in the text editor of your choice. For the purpose of this tutorial, the only required information is ``aws_access_key_id`` and ``aws_secret_access_key``. You can find these by logging into the AWS management console.
67
62
68
-
Next let's open ``service.py``, in it you'll find the following function:
63
+
Next let's open ``service.py``, in here you'll find the following function:
69
64
70
65
.. code:: python
71
66
@@ -77,28 +72,30 @@ Next let's open ``service.py``, in it you'll find the following function:
77
72
return e + pi
78
73
79
74
80
-
This is the hander function; this is what AWS Lambda will invoke in response to an event. You will notice that in the sample code provided ``e`` and ``pi`` are values looked up in a ``dict``. AWS Lambda uses the ``event`` parameter to pass in event data to the handler.
75
+
This is the hander function; this is the function AWS Lambda will invoke in response to an event. You will notice that in the sample code ``e`` and ``pi`` are values in a ``dict``. AWS Lambda uses the ``event`` parameter to pass in event data to the handler.
81
76
82
77
So if for example your function is responding to an http request, ``event`` will be the ``POST`` JSON data and if your function returns something, the contents will be in your http response payload.
83
78
84
-
Now let's open the ``event.json`` file. Here you'll find the values of ``e`` and ``pi`` that are being referenced in the sample code.
79
+
Next let's open the ``event.json`` file. Here you'll find the values of ``e`` and ``pi`` that are being referenced in the sample code.
85
80
86
81
If you now try and run:
87
82
88
83
.. code:: bash
89
84
90
85
(my_microservice) $ lambda invoke
91
86
92
-
"your test handler was successfully invoked!" should print out in your console. You've probably already put together that the ``lambda invoke`` command passes the values stored in the ``event.json`` file to your function.
87
+
"your test handler was successfully invoked!" should print out in your console.
88
+
89
+
As you probably put together, the ``lambda invoke`` command grabs the values stored in the ``event.json`` file and passes them to your function.
93
90
94
-
The ``event.json`` file should help you develop your Lambda service locally.
91
+
The ``event.json`` file should help you develop your Lambda service locally. You can specify an alternate ``event.json`` file by passing the ``--event=<filename>.json`` argument to ``lambda invoke``.
95
92
96
-
When you're ready to deploy your code to lambda simply run:
93
+
When you're ready to deploy your code to Lambda simply run:
97
94
98
95
.. code:: bash
99
96
100
97
(my_microservice) $ lambda deploy
101
98
102
-
The deploy script will evaluate your virtualenv and identify your project dependencies (actually just pip freeze). It will package these up along with your handler function to a zip file that it then uploads to AWS Lambda.
99
+
The deploy script will evaluate your virtualenv and identify your project dependencies. It will package these up along with your handler function to a zip file that it then uploads to AWS Lambda.
103
100
104
-
You can now log into the AWS Lambda management console to verify the code deployed successfully and wire it up to respond to an event.
101
+
You can now log into the AWS Lambda management console to verify the code deployed successfully.
0 commit comments