14
14
<http://docs.aws.amazon.com/lambda/latest/dg/with-s3-example-create-iam-role.html> `_
15
15
(of course you need one that can execute lambdas).
16
16
17
- In a new folder, create *mymodule.py *:
17
+ In a new folder, create *mymodule.py *.
18
18
19
19
.. code :: python
20
20
21
21
def hello (* args ):
22
22
return " Hello, world!"
23
23
24
24
25
- Then deploy the function (fill in your execution role resource name from the AWS
26
- console):
25
+ Then deploy the function (fill in your execution role resource name from the
26
+ AWS console).
27
27
28
28
::
29
29
30
30
awslambda . mybucket --create hello mymodule.hello arn:aws:iam::xxxxxxxxxxxx:role/myrole
31
31
32
32
33
+ When *awslambda * is done, you can test your new function in the Lambda
34
+ management console.
35
+
33
36
From now on, if you make changes to the function, just run:
34
37
35
38
::
36
39
37
40
awslambda . mybucket --update hello
38
41
39
42
40
- You can use as many options as you like (shown here with shorthand names):
43
+ You can use as many options as you like (some shown here with short names).
41
44
42
45
::
43
46
44
47
awslambda . mybucket -u hello -u myotherlambda --delete myoldlambda
45
48
46
49
47
- Or specify your functions in a YAML file (lets call it *sync.yaml *):
50
+ Or specify your functions in a YAML file (let's call it *sync.yaml *).
48
51
49
52
.. code :: yaml
50
53
@@ -55,28 +58,33 @@ Or specify your functions in a YAML file (lets call it *sync.yaml*):
55
58
# handler: myothermodule.myotherhandler
56
59
# role: arn:aws:iam::xxxxxxxxxxxx:role/myrole
57
60
58
- Syncing from a file, *awslambda * will update existing functions and create the
59
- others automatically.
61
+ When syncing from a file, *awslambda * will update existing functions and create
62
+ the others automatically.
60
63
61
64
::
62
65
63
66
awslambda . mybucket --sync sync.yaml
64
67
65
68
66
- To add dependencies, use your `pip * requirements.txt*
67
- <https://pip.readthedocs.io/en/stable/user_guide/#requirements-files> `_:
69
+ To add dependencies, use your `pip requirements file
70
+ <https://pip.readthedocs.io/en/stable/user_guide/#requirements-files> `_.
68
71
69
72
::
70
73
71
74
awslambda . mybucket -s sync.yaml --requirements requirements.txt
72
75
73
76
77
+ *Note that compiled dependencies * awslambda *downloads on your local machine
78
+ might not work on the AWS servers. Pure Python libraries should always work.
79
+ For others, it could be helpful to run * awslambda *itself in a Lambda function.
80
+ A process knows as * awslambdaception.
81
+
74
82
A template greeting page
75
83
........................
76
84
77
85
Let's use the features introduced above to create a greeting page. We will use
78
86
the `Jinja2<http://jinja.pocoo.org> `_ templating engine.
79
- Edit *mymodule.py *
87
+ Edit *mymodule.py *,
80
88
81
89
.. code :: python
82
90
@@ -99,21 +107,21 @@ Edit *mymodule.py*
99
107
' body' : template.render(parameters = event[' queryStringParameters' ])}
100
108
101
109
102
- And create your simple *requirements.txt *
110
+ and create a simple *requirements.txt *.
103
111
104
112
::
105
113
106
114
Jinja2
107
115
108
116
109
- Deploy
117
+ Deploy,
110
118
111
119
::
112
120
113
121
awslambda . mybucket -s sync.yaml -r requirements.txt
114
122
115
123
116
- Open the function in your AWS console. Go to *Triggers * and add an
124
+ then open the function in your AWS console. Go to *Triggers * and add an
117
125
*API Gateway * trigger. Set security to *Open * for now. Open the URL of the
118
126
created trigger in your browser. You should see "Hello, !". To customize the
119
127
page append e.g.
@@ -123,7 +131,7 @@ page append e.g.
123
131
?name=Commander Shepard&message=You've received a new message at your private terminal.
124
132
125
133
126
- to the URL.
134
+ to the URL and enjoy your serverless, templated webpage!
127
135
128
136
129
137
Usage
0 commit comments