What is AWS CLI and How to Setup and use AWS CLI to create and update Lambda function ?

Code With Travel
1 min readJun 1, 2021

The AWS Command Line Interface (AWS CLI) is an open source tool that enables you to interact with AWS services using commands in your command-line shell. With minimal configuration, the AWS CLI enables you to start running commands that implement functionality equivalent to that provided by the browser-based AWS Management Console from the command prompt in your terminal program:

https://www.youtube.com/watch?v=KqdQa1r71dc

If you plan to configure and use Lambda functions from the command line, install the AWS Command Line Interface (AWS CLI)

To set up the AWS CLI, see the following steps.

apt-get install awscliaws --version

It will ask for
AWS Access Key ID [None]: xxxxxxxxxx
AWS Secret Access Key [None]: xxxxxxxxxxxxxxxxxx
Default region name [None]: us-east-1
Default output format [None]: text

List the Lambda functions in your account

Get first 10 lambda function.

aws lambda list-functions --max-items 10

Now Retrive one lambda function

aws lambda get-function --function-name test_lambda_manish

Now let’s create function using AWS cli.

exports.handler = async function(event, context) {   console.log("ENVIRONMENT VARIABLES\n" + JSON.stringify(process.env, null, 2))   console.log("EVENT\n" + JSON.stringify(event, null, 2))   return context.logStreamName }

Copy the sample code into a file named index.jsand save to test_lambda folder.

Now create lambda_name.sh file and add following command.

cd test_lambda 
zip -X -r ../test_lambda.zip *
cd ..
aws lambda create-function-code --function-name arn:aws:lambda:ap-xxx-1:xxxxx:function:function-name --zip-file fileb://test_lambda.zip
rm test_lambda.zip

Now go to terminal and run following code.

./test_lambda.sh

--

--