Skip to content

safaa-alnabulsi/dsr-serverless-course

Repository files navigation

DSR Serverless Course (AWS Lambda)

Pre-requisites

  • Git
    • macOS: brew install git
    • Linux (Ubuntu): sudo apt-get update && sudo apt-get install git-all
  • conda
    • macOS

         wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O ~/miniconda.sh
         bash ~/miniconda.sh -b -p $HOME/miniconda
      

      For MacOS Catalina:

      If you are on macOS Catalina, the new default shell is zsh. You will instead need to run

         source <path to conda>/bin/activate && conda init zsh.
      
    • Linux (Ubuntu)

Creating AWS Account

Follow the instructions in this page

Preparing your local env

Clone the github repo

$ git clone [email protected]:safaa-alnabulsi/dsr-serverless-course.git
cd dsr-serverless-course

Create python3.6 virtual env, use

$ conda create -n dsr-serverless-py36 python=3.6 -y

Activate this environment, use

 $ conda activate dsr-serverless-py36

Install needed libraries, use

 $ pip install -r requirements.txt

Note: to deactivate an active environment, use

 $ conda deactivate

Intall zip command:

  • Ubuntu: sudo apt-get install -y zip

  • Manjaro: sudo pacman -S zip

    Note: In case if you get any error while installing the package, try the command below and repeat the previous commands sudo pacman -Rs zip

Configuring your local CLI with AWS

Before using aws-cli, you need to configure it with your AWS credentials. You can create a user in https://console.aws.amazon.com/iam/ and export the credentials csv. If the user name is cli-user, run the following:

$ aws configure --profile cli-user
AWS Access Key ID: foo
AWS Secret Access Key: bar
Default region name [us-west-2]: eu-west-1
Default output format [None]: json

$ export AWS_PROFILE=cli-user

If you have an issue

To test if you have access, run the following and you shouldn't see an error:

$  aws iam get-user
{
    "User": {
    "Path": "/",
    "UserName": "cli-user",
    "UserId": "HASH",
    "Arn": "arn:aws:iam::account-id:user/cli-user",
    "CreateDate": "2021-06-06T17:59:12Z"
  }
}

Note: If you have an issue in using the aws command try the following way in doing the setup:

$ cat > ~/.aws/config
[default]
region=us-west-2
aws_access_key_id=foo
aws_secret_access_key=bar

$ aws configure
AWS Access Key ID [****************foo]:
AWS Secret Access Key [****************bar]:
Default region name [us-west-2]:
Default output format [None]:

Note: using the new AWS CLI version 2 Docker image might not work with all examples.

Notes for Window users:

To create an env variable in Windows:

set ROLE_ARNN="value"

To create a variable which you use in your terminal

ROLE_ARNN="value"

To check its value

echo %ROLE_ARN%   on windows

So, to create Lambda For Windows (for tutorial 4,5,6)

set MY_NAME= Enter your name
aws lambda create-function --function-name %MY_NAME%-function-from-cli --runtime python3.6 --handler lambda_function.lambda_handler --role %ROLE_ARN% --zip-file fileb://my_lambda.zip

Tutorials & Labs

Introduction

To learn more, follow this tutorial 00-intro.md

AWS Console General Introduction

To learn more, follow this tutorial 01-aws-console-general-intro.md

Create lambda from a blurprint using aws console

To learn more, follow this tutorial 02-create-lambda-from-blueprint-with-aws-console.md

Create lambda from scratch using aws console

To learn more, follow this tutorial 03-create-lambda-from-scratch-with-aws-console.md

Create & use lambda using aws-cli

To learn more, follow this tutorial 04-create-lambda-with-aws-cli.md

Easy setup and deployment using shell scripts

To learn more, follow this tutorial 05-create-lambda-with-aws-cli-and-shell-scripts.md

Text to speech example, using boto3 (Python SDK)

To learn more, follow this tutorial 06-text-to-speech-lambda-boto3-and-polly.md

References