Taught by Noah Coad, Senior IoT Architect at AWS
at the Dallas Makerspace on 2019-05-24 and 2019-06-27
Amazon Web Services (AWS) provides essential building blocks to creating your own applications. Like code in the cloud (AWS Lambda), image recognition detection (AWS Rekognize), database (AWS DynamoDB), file storage (S3), etc. Through this course you'll get started on combining 6 of these AWS services together to build a cloud app that you can submit an image to, store it, detect elements in the image, store those in a database, and manage it all through a REST API. We'll be using a Python framework for AWS called AWS Chalice, which makes coding, connecting, testing, and deploying these components real easy.
- Intro Video that walks through these steps
- Prezi Presentation
- Class info and register at: Dallas Makerspace Event
- Walking through this workshop:
AWS Chalice Media Query Application - AWS Free Tier account: https://aws.amazon.com/free
- Use an AWS Cloud9 Development Environment at https://aws.amazon.com/cloud9/
Note: Cloud9 uses temporary credentials by default, which AWS Chalice can not deploy with. So an IAM Role with an AdministativeAccess policy must be attached to the Cloud9 EC2 instance. See the "Getting Started Walkthrough" section below for details on setting this up. - Please provide feedback on the course at: Event Feedback
- If you'd like to be notified of future classes, please add your info here: Signup for Event Notices
- Help me get to 1000 Twitter followers =) https://twitter.com/noahcoad
- Realted Local Meetup Groups: AWS DFW Official, DFW Pythoneers, AWS User Group, AWS On Tap, AWS Cloud, AWS Deep Dives, Python for Everyone, DFW Pythoneers, PyMavs, dot_py, Coding Temple Dallas, Learn to Code, Coding Dojo
- Dallas Makerspace Info: Homepage, Other Events, and Open House Tours are Thursdays at 7:00pm
This will walk you through each step to get started from never having used AWS before to your first AWS Lambda code running in the cloud. Watch intro video walks through these steps.
Create a new AWS account if you don't have one already.
- Create a free AWS account at https://aws.amazon.com/free
A credit card is required. But all the services used here remain under the free tier level. - Log into your new free account here: AWS Console Login
- Switch region to "Oregon" if it's not already ...
Top right of console click "N. Virginia" if you see it, and select "US West (Oregon)"
Use a free Cloud9 development environment in the cloud on any computer (Windows, Mac, Linux, Chromebook, etc) for a consistent and easy way to start coding.
- Create a Cloud9 environment by clicking the orange 'Create environment' button at https://us-west-2.console.aws.amazon.com/cloud9/home/product?region=us-west-2#
- Name it "Chalice Walkthrough"
- Accept all other defaults on the following pages
- Open a new tab and create a new IAM Role at https://console.aws.amazon.com/iam/home#/roles
- Click blue "Create Role"
- Choose "EC2" from list, then click blue "Next: Permissions"
- Check the "AdministativeAccess" policy checkbox, then click the blue "Next: Tags" button, then "Next: Review"
- Give it the name "cloud9_admin" and click "Create role"
- Attach new role to the Cloud9 EC2 virtual machine at https://us-west-2.console.aws.amazon.com/ec2/v2/home?region=us-west-2#Instances:search=cloud9;sort=tag:Name
- Right-click the item in the list with "cloud9" in it's name
- Select 'Instance Settings' > 'Attach/Replace IAM Role'
- From the drop-down list, select the "cloud9_admin" role from earlier, then the blue "Apply" button
- Go into your new "Chalice Walkthrough" Cloud9 environment at https://us-west-2.console.aws.amazon.com/cloud9/home?region=us-west-2 ... and click the "Open IDE" button
- Turn off temporary credentials by selecting the "AWS Cloud9" bold menu item at the top > "Preferences" > "AWS Settings" in the list > "Credentials" > and turn off the "AWS managed temporary credentials" switch
This replaces the Part 0: Introduction to AWS Lambda and Chalice walkthrough using the Cloud9 development environment for consistency.
- Make a large terminal window by clicking the "Window" menu > "New Terminal" and enter these commands
# creates a new ~/.aws/config file needed by AWS Chalice
echo [default] > ~/.aws/config
echo region=us-west-2 >> ~/.aws/config
# create a new python app environment
virtualenv chalice-env
# intializes the new python app environment
source chalice-env/bin/activate
# installs the AWS Chalice python framework
pip install chalice
# creates a new chalice project called 'workshop-intro'
chalice new-project workshop-intro
# change into the folder and list files
cd workshop-intro
ls
Click app.py
to open it in the editor and replace ALL the contents with...
from chalice import Chalice
app = Chalice(app_name='workshop-intro')
@app.lambda_function()
def hello_world(event, context):
return {'hello': 'world'}
Save the file ("File" menu > "Save"), then back in the terminal...
# deploys the new code to the AWS Lambda cloud
chalice deploy
# runs the AWS Lambda in the cloud
chalice invoke -n hello_world
View your new lambda at https://us-west-2.console.aws.amazon.com/lambda/home?region=us-west-2#/functions?f0=a3c%3D%3Ad29ya3Nob3AtaW50cm8%3D
Now add another method that uses a parameter by adding these lines to the end of app.py
...
@app.lambda_function()
def hello_name(event, context):
name = event['name']
return {'hello': name}
Save file, then redeploy and run with...
# redeploy the latest updates
chalice deploy
# run the new lambda, and pass in a simple JSON object as input
echo '{"name": "Kyle"}' | chalice invoke -n hello_name
Notice you've now created two lambda at https://us-west-2.console.aws.amazon.com/lambda/home?region=us-west-2#/functions?f0=a3c%3D%3Ad29ya3Nob3AtaW50cm8%3D
You can also see these lambdas by running...
# use AWS command line tool to list functions
aws lambda list-functions
# a little fancier, use the jq tool to filter to just the function names
sudo yum install -y jq
aws lambda list-functions | jq '.Functions[].FunctionName'
Finally delete the lambdas so far with...
# deletes the deployed AWS resources
chalice delete
Now continue the walkthrough here: https://chalice-workshop.readthedocs.io/en/latest/media-query/01-intro-rekognition.html
As a bonus, check out the REST APIs w Chalice video.