Create Lambda Funtions using Serverless Framework

Ubuntu20.04 VM Configuration

Miniconda
(1)Access to Miniconda documentation
https://docs.anaconda.com/free/miniconda/index.html
(2)Installed Python3.9 Miniconda Installer, Linux 64bit os
ServerlessLambda1

bash Miniconda3-py39_24.1.2-0-Linux-x86_64.sh

ServerlessLambda2

Install Visual Studio Code
ServerlessLambda4
Ubuntu Software > Search for Visual Studio Code > Click on 설치
ServerlessLambda5
Install Extensions > Python
Install pip3

sudo apt update
sudo apt install python3-pip
pip3 --version
sudo pip3 install --upgrade pip
sudo pip3 install testresources

Reference: https://www.webhi.com/how-to/how-to-install-pip3-in-ubuntu/
Docker Installation
Version: Ubuntu Focal 20.04 (LTS)
(1)Uninstall all conflicting packages

for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

If you have installed the containerd or runc previously, uninstall them to avoid conflicts with the versions bundled with Docker Engine
Install using the apt repository
(2)Set up Docker’s apt repository

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

(3)Install the Docker packages

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

To install the latest version, run the command
(4)Verify that the Docker Engine installation is successful by running the hello-world image

sudo docker run hello-world

ServerlessLambda6
Reference:
https://docs.docker.com/engine/install/ubuntu/

Installing Serverless Framework
Nodejs Installation failed persistently, so I tried an alternative route
(1)Install the lastest version

curl -o- -L https://slss.io/install | bash

(2)Upgrade

serverless upgrade

# You can also restrict the upgrade to the latest v2 version:
curl -o- -L https://slss.io/install | VERSION=2.72.2 bash

Upgrade Serverless Framework to the latest version
(3)Installation Completed
ServerlessLambda7
Reference:
https://www.serverless.com/framework/docs-install-standalone

Virtual Environment
(1)Create Virtual Environment

conda create -n sloshinga-dev python=3.9

ServerlessLambda10
(2)Activate Virtual Environment

conda activate sloshinga-dev

ServerlessLambda11
(3)Install packages needed for lambda handler function

conda install <pkgs>

ServerlessLambda12
(4)Deactivate Virtual Environment

conda deactivate

AWS Credentials

sudo sls config credentials --provider aws --key <Access Key> --secret <Secret Key>

ServerlessLambda20

Deploy Serverless
Had the pre-made lambda file as zip
(1)Install the library zip

sudo apt update
sudo apt install unzip

(2)Install node.js & npm
Activate virtual env

conda activate sloshinga-dev

ServerlessLambda11

sudo apt install nodejs

ServerlessLambda15
The Serverless Framework is a Node.js application
Node.js provides the runtime environment that executes the JavaScript code of the Serverless Framework
Without Node.js installed, you can’t run any Node.js applications, including the Serverless Framework

node -v
npm -v

ServerlessLambda19
Check whether nodejs and npm packages are successfully installed by checking their versions

(3)Extract the zip file inside the directory sloshing-service

mkdir sloshinga-service
cd sloshinga-service/
ls -l
unzip sloshing-predictiona.zip

ServerlessLambda16

(4)Confirm whether the Lambda Handler function works in a local environment

code

Open visual studio code and open the sloshing-predictiona folder
ServerlessLambda18
Open handler.py code > Select the virtual env terminal
ServerlessLambda17
Run the code => Successful
(5)Install/Update Serverless

sudo npm install -g serverless

ServerlessLambda21
(6)Deploy the whole folder

sudo serverless deploy

ServerlessLambda22
(7)When Lmabda is executed using the enpoint API

https://<endpoint>

ServerlessLambda23
For this reason, the additional lambda, implemented previously, was needed
Another lambda function, which passes the parameters, takes care of this problem
Reference: https://blog.zer01ne.dev/entry/AWS-%EB%A5%BC-%EC%82%AC%EC%9A%A9%ED%95%9C-%EC%84%9C%EB%B2%84%EB%A6%AC%EC%8A%A4-%EC%95%84%ED%82%A4%ED%85%8D%EC%B3%90-%EC%A0%81%EC%9A%A9%EA%B8%B0%EC%82%BD%EC%A7%88%EA%B8%B0-4-serverless-%ED%94%84%EB%A0%88%EC%9E%84%EC%9B%8C%ED%81%AC