Lambda Functions
- Lambda by Amazon Web Services (AWS) is an analogous serverless solution.
- Lambda can be used internall as well as for model deployments (we are focusing on the latter).
- We will repeat setting up the weather app and the recommender model, using the CLI (command line interface tools)
![aws](aws.png)
Aside: Setting up an IAM user
Hello World in Lambda
- Select the lambda service.
![lambda_start](lambda_start.png)
- Pick the python 3.7 runtime.
![lambda_scratch](lambda_scratch.png)
- You will see the green bar indicating a successful creation.
![lambda_start_success](lambda_start_success.png)
- We will initially not changed the code.
![lambda_hello_world](lambda_hello_world.png)
![lambda_hello_world_test](lambda_hello_world_test.png)
- The result looks like this.
![lambda_hello_world_test_result](lambda_hello_world_test_result.png)
Setting up an API Gateway
- We will slightly change the function so that it forms a proper HTTP response.
![lambda_api0](lambda_api0.png)
- Under the Designer section, we will ‘Add Trigger’ and select ‘API Gateway’.
![lambda_api1](lambda_api1.png)
![lambda_api2](lambda_api2.png)
- We choose HTTP API and security to be open for the time being.
![lambda_api3](lambda_api3.png)
- A block will appear on the designer tab in the Lambda function page.
![lambda_api4](lambda_api4.png)
- Once you click on the API Gateway link provided, you will see the response as expected:
![lambda_api5](lambda_api5.png)
![lambda_api6](lambda_api6.png)
See this documentation for more details.
Set up a Programmatic User to Access S3
What is IAM? IAM (Identity and Access Management) is a very useful tool for an organization to administer and control access to various resources.
- We will create a programmatic user, similar to the service account in GCP.
What is S3? S3 (Simple Storage Service) is a very popular service used by many large and small companies and individuals.
- For example, a typical data science work flow may involve ETL work on databases (such as Amazon Redshift) and then storing outputs on S3.
Start with finding the IAM service.
![iam](iam.png)
- Click on create a new user.
![iam1](iam_create1.png)
- We will make this user have programmatic access (for example via Python later on).
![iam2](iam_create2.png)
- For now, we let the user have full read and write access to S3.
![iam3](iam_create3.png)
- Lets review the user setup.
![iam4](iam_create4.png)
- In this step, copy the access key and secret key that will be needed for the programmatic access. They will not be shown again, so store them safely and securely.
![iam5](iam_create5.png)
- Here is the description of the user we just created.
![iam6](iam_create6.png)
Set up AWS CLI
The AWS Command Line Interface (CLI) is a unified tool to manage your AWS services. With just one tool to download and configure, you can control multiple AWS services from the command line and automate them through scripts.
- Head over to https://aws.amazon.com/cli/ and download a suitable installer for your OS.
Install it and open your terminal. If it is in the PATH, you should be able to verify the following:
which aws
#/usr/local/bin/aws #your location could be different.
aws --version
#aws-cli/2.0.45 Python/3.7.4 Darwin/18.6.0 exe/x86_64
Using the access and secret keys to configure aws using the aws configure
command.
![](cli_configure.png)
Test S3 access by issing the following commmand: aws s3 ls
$ aws s3 ls
2020-09-03 12:27:48 chicagodatascience-com
2020-09-03 12:02:25 theja-model-store
Instead of programmatically creating a bucket (with the aws s3 mb s3://bucket-name
) we will do it using the GUI below.