Serverless Commands

sls create -t aws-nodejs -p myService
sls deploy
sls invoke -f hello

Ref: https://www.serverless.com/framework/docs/providers/aws/examples/hello-world/node/

sls create -t aws-python3 -p myService
sls deploy
sls invoke -f hello

Ref: https://www.serverless.com/framework/docs/providers/aws/examples/hello-world/python/

sls info
sls remove

How to Setup Password Authentication For AWS EC2 Instances

  1. Log in to the server using ssh client of your choice using the private key.

ssh -i your-key.pem username@(public-ip-address)

  1. Open the sshd_config file.

sudo vi /etc/ssh/sshd_config

  1. Find the line containing “PasswordAuthentication” parameter and change its value from “no” to “yes“

PasswordAuthentication yes

  1. Setup ec2 user password using the “passwd” command.

sudo passwd ubuntu

  1. Now, restart the “sshd” service using the following command.

sudo service sshd restart

  1. Now you can log out and log in using the password you set for the user. For example,

ssh ubuntu@35.162.225.240

How to fix wkhtmltopdf in AWS Amazon Linux EC2 older version?

Error:

wkhtmltopdf: error while loading shared libraries: libpng15.so.15: cannot open shared object file: No such file or directory

Solution:

  1. wget https://sourceforge.net/projects/libpng/files/libpng15/older-releases/1.5.15/libpng-1.5.15.tar.gz/download -O libpng-1.5.15.tar.gz
  2. tar -zxvf libpng-1.5.15.tar.gz
  3. cd libpng-1.5.15
  4. sudo yum groupinstall -y "Development Tools"
  5. ./configure --prefix=/usr
  6. sudo make install
  7. sudo yum install -y libtiff
Ref: https://majestic.cloud/how-to-install-wkhtmltopdf-on-amazon-linux/

Error:

Kerning error in pdf document created

Solution:

  • sudo wget http://pastebin.com/raw.php?i=AmfYN3er -O /etc/fonts/conf.d/10-wkhtmltopdf.conf
Ref: https://www.jeremydaly.com/how-to-install-wkhtmltopdf-on-amazon-linux/

AWS EC2 vs Lambda hosting

EC2 - CodeStar Lambda - CodeStar Lambda - Chalice Lambda - Serverless Lambda - Zappa
Uses EC2 instances Uses AWS Lambda and API Gateway Uses S3, AWS Lambda and API Gateway
Can run in local environment Cannot run in local environment Can run in local environment Cannot run in local environment Can run in local environment
Cheapest config: Free tier - t2.micro - 1 vCPU - 1 GB Memory - 8 GB EBS Cheapest config: 128 MB Memory
Based on Servers installed in EC2. For Eg: Python Flask or Node Serverless. Based on lambda functions and layers Serverless. Based on lambda functions and layers. Uses Chalice micro framework Serverless. Based on lambda functions and layers. Uses Serverless framework Serverless. Based on lambda functions and layers. Uses Zappa micro framework
Supports Python, Nodejs, etc Supports Python Supports Python, Nodejs, etc Supports Python
Supports Flask and Flask-Restful No support for Flask Flask like routing No support for Flask. Supports Flask. Seems not supporting Flask-Restful
Flask file structure No specific file structure Multi file structure using blueprints Single file structure
1 EC2 + 1 Code Pipeline 1 Lambda Function + 1 Code Pipeline 1 Lambda Function 1 Lambda Function for each route 1 Lambda Function
t2.micro: 1GB Default Memory: 128MB Default Memory: 128MB Default Memory: 1024MB Default Memory: 512MB
Dependency added using pip and build scripts Dependency added using pip and lambda layers Dependency added using requirements.txt and lambda layers Dependency added using yml Dependency added using virtual env
Available when EC2 is on 24x7
Dynamic IP or URL.
Static IP is billed.
No dynamic IP or URL.
Free Static URL.
750 EC2 hours/month free.
30 GB EBS free.
1 Million request/month free.
3.2 Million exec seconds/month free.
Free tier for 1 year. Lambda: Free tier for ever.
API Gateway: Free tier for 1 year.
Suitable for complex REST based Web Services and Web Apps. Suitable for simple web services and static Web Apps.
Best for demo or hobby use.
Not suitable for apis with low level dependencies.
No limitation on api execution time Lambda time limit: 15 minutes
API Gateway time limit: 30 seconds
Runs over http Runs over https
Restful APIs. Flask routing. Functions mapped as APIs Restful APIs. Flask like routing. Restful APIs. Routing in yml Restful APIs. Flask routing
Trivial stand alone APIs are not recommened. Advanced or complex or low level implementations are not recommended.

How to create lambda layers?

Example: Create requests layer

$ mkdir python
$ cd python
$ pip install requests -t .
$ cd ..
$ zip -r python.zip python

Rename the zip file to requests.zip
Create a lambda layer by uploading this zip file.

How to run commands at machine startup?

OS: Amazon Linux
Add your commands in /etc/rc.local

Where to check for AWS CodeStar deployment logs in EC2?

/opt/codedeploy-agent/deployment-root/deployment-group-ID/deployment-ID/logs/scripts.log