Skip to content

Commit ff6f2eb

Browse files
committed
finish up aws lambda python 3.6 post
1 parent 69042ff commit ff6f2eb

File tree

12 files changed

+60
-41
lines changed

12 files changed

+60
-41
lines changed

content/pages/07-web-development/31-aws-lambda.markdown

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,18 @@ uploads to [AWS' Simple Storage Service (S3)](https://aws.amazon.com/s3/).
1515

1616
<a href="https://aws.amazon.com/lambda/" style="border:none"><img src="/img/logos/aws-lambda.jpg" width="100%" alt="AWS Lambda logo." class="technical-diagram" style="border-radius:6px"></a>
1717

18+
1819
## Why is Lambda useful?
1920
Lambda is often used as a "serverless" compute architecture, which
2021
allows developers to upload their Python code instead of spinning and
2122
configuring servers, deploying their code and scaling based on traffic.
2223

24+
2325
## Python on AWS Lambda
24-
Lambda only had support for JavaScript when it was first released in
25-
late 2014. Python 2 developers were welcomed to the platform less than a
26-
year after its release, in October 2015. Now that Lambda has support for both Python 2.7 and 3.6
26+
Lambda only had support for JavaScript, specifically Node.JS, when it was
27+
first released in late 2014. Python 2 developers were welcomed to the
28+
platform less than a year after its release, in October 2015. Lambda now
29+
has support for both Python 2.7 and 3.6.
2730

2831

2932
### Python-specific AWS Lambda resources
@@ -35,10 +38,8 @@ year after its release, in October 2015. Now that Lambda has support for both Py
3538
### General AWS Lambda resources
3639
* [The Serverless Start-Up - Down With Servers!](http://highscalability.com/blog/2015/12/7/the-serverless-start-up-down-with-servers.html)
3740

38-
* [](http://www.allthingsdistributed.com/2016/06/aws-lambda-serverless-reference-architectures.html)
41+
* [AWS Lambda Serverless Reference Architectures](http://www.allthingsdistributed.com/2016/06/aws-lambda-serverless-reference-architectures.html)
3942

4043
* The
4144
[AWS Lambda tag](https://aws.amazon.com/blogs/aws/category/aws-lambda/)
4245
on the official AWS blog contains all the related first-party tutorials
43-
and announcement
44-

content/posts/170428-python-2-7-aws-lambda.markdown

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,15 @@ We should see a success message on the next page just below the
160160

161161
<img src="/img/170428-aws-lambda-python-2-7/save-and-test.jpg" width="100%" class="technical-diagram img-rounded bordered" alt="Save and test button.">
162162

163-
Click that "Save and test" button to execute the Lambda. At first it
164-
may appear that nothing happened but scroll down to the "Execution result"
165-
section where we can see our output.
163+
Press the "Test" button to execute the Lambda. Lambda prompts us for
164+
some data to simulate an event that would trigger our function. Select
165+
the "Hello World" sample event template, which contains some example keys.
166+
Our Lambda will not those keys in its execution so it does not matter what
167+
they are. Click the "Save and test" button at the bottom of the modal.
168+
169+
<img src="/img/170428-aws-lambda-python-2-7/sample-event-template.jpg" width="100%" class="technical-diagram img-rounded bordered" alt="Sample event template for our Lambda execution.">
170+
171+
Scroll down to the "Execution result" section where we can see our output.
166172

167173
<img src="/img/170428-aws-lambda-python-2-7/execution-results.jpg" width="100%" class="technical-diagram img-rounded bordered" alt="Execution results from running our Lambda function.">
168174

content/posts/170429-python-3-6-aws-lambda.markdown

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ comes in to API Gateway or a new file is uploaded to
1515
[AWS S3](https://aws.amazon.com/s3/) then AWS Lambda can execute a function
1616
to respond to that API call or manipulate the file on S3.
1717

18-
AWS Lambda is not related in any way to Python's `lambda` syntax. The
19-
`lambda` keyword in Python is used to create anonymous functions within the
20-
programming language and AWS Lambda's name just happens to collide with
21-
the existing Python feature.
18+
AWS Lambdas are not related to the Python languages' `lambda` expressions.
19+
The AWS Lambda name just happens to collide with the the `lambda` keyword
20+
name in Python that is used to create anonymous functions.
2221

2322
Let's learn how to quickly write and run a Lambda function to execute
2423
basic Python 3.6 code which uses environment variables as input.
@@ -29,9 +28,14 @@ changed so that you can build much more complicated Python programs.
2928
## Our Tools
3029
No local [development environment](/development-environments.html) tools
3130
are required for this tutorial, other than a web browser. All the work will
32-
happen on AWS via their Console. All of these steps can also be completed
33-
from the command line via the [boto3](https://boto3.readthedocs.io/en/latest/)
34-
library, but we won't cover that in this post.
31+
happen on AWS via their Console.
32+
33+
These steps can also be completed from the command line via the
34+
[boto3](https://boto3.readthedocs.io/en/latest/) library, but we won't
35+
cover that in this post.
36+
37+
If using Python 2 is still your jam rather than Python 3, take a look at
38+
[this other post which shows how to execute Python 2.7 code on AWS Lambda](/blog/aws-lambda-python-2-7.html).
3539

3640
Sign up for a new [Amazon Web Services account](https://aws.amazon.com/)
3741
(which provides a generous free tier), or use your existing AWS account.
@@ -149,7 +153,7 @@ required function configuration items.
149153

150154
Keep the default handler set to `lambda_function.lambda_handler`. Select
151155
"Create a new Role from template(s)" from the drop-down then for the
152-
"Role name" field enter "dynamodb_permissions". Under "Policy templates"
156+
"Role name" field enter "dynamodb_access". Under "Policy templates"
153157
select the "Simple Microservice permissions".
154158

155159
The "Simple Microservice permissions" allows our Lambda to access
@@ -159,46 +163,53 @@ temporary storage for Lambda functions.
159163

160164
<img src="/img/170429-aws-lambda-python-3-6/lambda-handler-and-role.jpg" width="100%" class="technical-diagram img-rounded bordered" alt="For the final configuration, keep the default handler, create a new role from a template for Simple Microservice permissions and save it with a unique name.">
161165

162-
Now that our code and configuration is in place, click the "Next" button
166+
Our code and configuration is in place so click the "Next" button
163167
at the bottom right corner of the page.
164168

165-
<img src="/img/170428-aws-lambda-python-2-7/review-lambda.jpg" width="100%" class="technical-diagram img-rounded bordered" alt="We can review the values set during our configuration.">
169+
<img src="/img/170429-aws-lambda-python-3-6/review-lambda.jpg" width="100%" class="technical-diagram img-rounded bordered" alt="Review Lambda configuration.">
170+
171+
The review screen shows us our configuration settings to make sure we
172+
selected the appropriate values for our new Lambda function. Scroll down
173+
press "Create function".
174+
175+
<img src="/img/170429-aws-lambda-python-3-6/create-function.jpg" width="100%" class="technical-diagram img-rounded bordered" alt="Click the create function button to continue.">
166176

167-
The review screen will show us our configuration settings. Scroll down
168-
to the bottom and click the "Create function" button to continue.
177+
Success message should appear on the next page below the "Test" button.
169178

170-
<img src="/img/170428-aws-lambda-python-2-7/create-function.jpg" width="100%" class="technical-diagram img-rounded bordered" alt="Click the create function button to continue.">
179+
<img src="/img/170429-aws-lambda-python-3-6/test.jpg" width="100%" class="technical-diagram img-rounded bordered" alt="Test button on the execution screen.">
171180

172-
We should see a success message on the next page just below the
173-
"Save and test" button.
181+
Click the "Test" button to execute the Lambda. Lambda will prompt us for
182+
some data to simulate an event that would kick off our function. Select
183+
the "Hello World" sample event template, which contains some keys but our
184+
Lambda will not use that in its execution. Click the "Save and test" button
185+
at the bottom of the modal.
174186

175-
<img src="/img/170428-aws-lambda-python-2-7/save-and-test.jpg" width="100%" class="technical-diagram img-rounded bordered" alt="Save and test button.">
187+
<img src="/img/170429-aws-lambda-python-3-6/sample-event-template.jpg" width="100%" class="technical-diagram img-rounded bordered" alt="Sample event template for Lambda execution.">
176188

177-
Click that "Save and test" button to execute the Lambda. At first it
178-
may appear that nothing happened but scroll down to the "Execution result"
179-
section where we can see our output.
189+
Scroll down to the "Execution result" section where we can see our output.
180190

181-
<img src="/img/170428-aws-lambda-python-2-7/execution-results.jpg" width="100%" class="technical-diagram img-rounded bordered" alt="Execution results from running our Lambda function.">
191+
<img src="/img/170429-aws-lambda-python-3-6/execution-results.jpg" width="100%" class="technical-diagram img-rounded bordered" alt="Results from executing our new Lambda function.">
182192

183-
We get the log output that shows us the return value of our function. In
184-
this case it is the string message from `what_to_print`. We can also see
185-
down below that our print function produced output five times.
193+
The log output shows us the return value of our function, which in this
194+
execution was the string message from `what_to_print`. We can also see
195+
our print function produced output five times as expected based on the
196+
amount set in the `how_many_times` environment variable.
186197

187198

188199
## Next Steps
189-
Awesome, you just configured, wrote and executed your first Python 3.6
190-
code on AWS Lambda! The real power of Lambda comes in when you connect a
191-
trigger to it so your code executes based on events. We'll take a look
192-
at that in the next tutorial.
200+
You just configured, coded and executed your first Python 3.6 AWS Lambda
201+
function! The real power of Lambda comes in when you use triggers to
202+
your Lambda function so it executes based on events that happen.
203+
We will take a look at that in the next tutorial.
193204

194-
What else can you do with Python and Lambda? Take a look at the
195-
[AWS Lambda](/aws-lambda.html) page for more examples and tutorials.
205+
Take a look at the [AWS Lambda](/aws-lambda.html) page for additional
206+
examples and tutorials that other folks have shared for Lambda with Python.
196207

197208
Questions? Contact me via Twitter
198209
[@fullstackpython](https://twitter.com/fullstackpython)
199210
or [@mattmakai](https://twitter.com/mattmakai). I am also on GitHub with
200211
the username [mattmakai](https://github.com/mattmakai).
201212

202213
Something wrong with this post? Fork
203-
[this page's source on GitHub](https://github.com/mattmakai/fullstackpython.com/blob/master/content/posts/170428-python-2-7-aws-lambda.markdown).
214+
[this page's source on GitHub](https://github.com/mattmakai/fullstackpython.com/blob/master/content/posts/170429-python-3-6-aws-lambda.markdown).
204215

67.9 KB
Loading
-40.8 KB
Loading
92.1 KB
Loading
50.8 KB
Loading
29.3 KB
Loading
67.9 KB
Loading
-69.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)