AWS Lambda CLI Setup with Deployment Script
In this tutorial, we will learn many things, so, don’t get puzzled!
- AWS CLI installation and configure.
- APEX installation.
- Create a Lambda function from CLI.
- Deploy a Lambda function from CLI.
Let’s get started!
AWS CLI installation and configure
Prerequisites:
You must ensure that you have at least Python 2 version 2.6.5+ or Python 3 version 3.3+ installed. To verify your current version, run the command:
python --versionInstallation:
The recommendation for installing the AWS CLI is to use the bundled installer provided by AWS. The bundled installer includes all dependencies required for the installation.
1. To begin the installation run the following command:
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"2. Next, you must unzip the downloaded package from step 1:
unzip awscli-bundle.zip3. Once the package is unzipped, you can run the installation:
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/awsUsing the -b option allows all users to use the AWS CLI from any directory, meaning you will not need to specify the install directory in the user’s $PATH variable.
Configure:
To configure AWS CLI we need three things
AWS_ACCESS_KEY_IDAWS account access keyAWS_SECRET_ACCESS_KEYAWS account secret keyAWS_REGIONAWS region
for these three things login to your AWS console and click on your account > My Security Credential > Create access Key

now you have everything to enter in AWS world :)
run this command on your terminal
aws configurenow it will ask for AWS_ACCESS_KEY_ID , AWS_SECRET_ACCESS_KEY and AWS_REGION
All set for AWS CLI
APEX installation
Installation
On macOS, Linux, or OpenBSD run the following:
curl https://raw.githubusercontent.com/apex/apex/master/install.sh | shThis command will install apex binary as /usr/local/bin/apex and you may need to run the sudo the version below, or alternatively/usr/local:
curl https://raw.githubusercontent.com/apex/apex/master/install.sh | sudo shYou can specify a destination as below
curl https://raw.githubusercontent.com/apex/apex/master/install.sh | DEST=$HOME/bin/apex shthis command will install apex binary as $HOME/bin/apex and you may not need to use sudo.
On Windows download binary.
If already installed, upgrade with:
apex upgradeDone!
Create a Lambda function from CLI
To create a Lambda function open terminal and run:
apex initit will ask for the project name which will be your lambda function name.
the good thing about this, it will create the role for lambda execute, no need to worry.

index.js is your entry file for the lambda function. Play with it as you want…..
go to your AWS console in browser and create a Lambda function with the same name which you provided on apex init

rename your local folder hello to YOUR_FUNCTION_NAME

Deploy a Lambda function from CLI
Heres the tricky part comes...
create a file deploy.sh inside your lambda folder

write down this code inside the file
FIRST_ARGUMENT="$1"echo "deploying $FIRST_ARGUMENT..."zip -r function.zip *aws lambda update-function-code --function-name $FIRST_ARGUMENT --zip-file fileb://function.ziprm function.zipecho "$FIRST_ARGUMENT successfully deployed."
now make the .sh file executable by running this command
chmod +x deploy.shnow everything is done!
just run the deploy.sh file and it will automatically do the rest for you!
./deploy.sh YOUR_FUNCTION_NAMEEnding
If you like such automation on AWS for Lambda, then Follow me, I’ll post many more of them soon. Thanks for supporting! Happy coding!