Skip to content

Commit

Permalink
lambda part 02
Browse files Browse the repository at this point in the history
  • Loading branch information
macielcalebe committed Sep 2, 2024
1 parent 3fb4a8f commit 144890f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 7 deletions.
2 changes: 1 addition & 1 deletion content/classes/07-lambda/lambda_practicing.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ with open("my_lambda.zip", "rb") as f:

lambda_response = lambda_client.create_function(
FunctionName=function_name,
Runtime="python3.9",
Runtime="python3.10",
Role=lambda_role_arn,
Handler="my_lambda.say_hello", # Python file DOT handler function
Code={"ZipFile": zip_to_deploy},
Expand Down
77 changes: 77 additions & 0 deletions content/classes/07-lambda/sa_lambda_function.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,83 @@

Let's create a lambda function that uses the `textblob` library to return the polarity of a text.

But first, let's configure the AWS CLI so we have another way to interact with our resources created in AWS.

## AWS CLI - Command Line Interface

### Install

[**Click Here**](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) to install AWS CLI.

### Configure

Configure the region and credentials provided by the professor.

<div class="termy">

```console
$ aws configure --profile mlops
AWS Access Key ID [None]: ????????????
AWS Secret Access Key [None]: ????????????????????????????????
Default region name [None]: us-east-2
Default output format [None]:
```

</div>
<br>

### Set profile

To set a default profile, use:

=== "Linux"

<div class="termy">

```console
$ export AWS_PROFILE=mlops
```

</div>
<br>

=== "Windows CMD (Command Prompt)"

<div class="termy">

```console
$ export AWS_PROFILE=mlops
```

</div>
<br>

=== "Windows PowerShell"

<div class="termy">

```console
$ env:AWS_PROFILE = "mlops"
```

</div>
<br>

### Example: list Lambda functions

You can now use the AWS CLI to create, list, or remove resources. For example, to list the names of lambda functions:

<div class="termy">

```console
$ aws lambda list-functions --query "Functions[*].FunctionName" --output text
```

</div>
<br>

From here on, you can research how to do with the AWS CLI what we did with `boto3` library.

## Create source code

!!! exercise "Question"
Expand Down
5 changes: 3 additions & 2 deletions content/classes/07-lambda/sentiment_analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Looking back at the examples we did, they involved a [*function that returned a

Let's use this class to build more complex examples using AWS Lambda!

!!! progress "Click to continue"
<!-- !!! progress "Click to continue" -->

## Sentiment Analysis

Expand Down Expand Up @@ -106,4 +106,5 @@ print(f"Polarity of text3: {blob3.polarity}")
!!! tip "Tip!"
Here it is the repository of textblob: https://github.com/sloria/textblob

Run this code locally and test it with other sentences. Then proceed to the next topic.
!!! exercise "Question"
Run this code locally and test it with other sentences. Then proceed to the next topic.
8 changes: 4 additions & 4 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ nav:
- classes/07-lambda/aws_lambda.md
- classes/07-lambda/lambda_practicing.md
- classes/07-lambda/api_gateway.md
# - "Part 2":
# - classes/07-lambda/sentiment_analysis.md
# - classes/07-lambda/sa_lambda_function.md
# - classes/07-lambda/lambda_layer.md
- "Part 2":
- classes/07-lambda/sentiment_analysis.md
- classes/07-lambda/sa_lambda_function.md
- classes/07-lambda/lambda_layer.md
# - "Part 3":
# - classes/07-lambda/lambda_quotas.md
# - classes/07-lambda/lambda_and_docker.md
Expand Down

0 comments on commit 144890f

Please sign in to comment.