Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call aws-cli from AWS Lambda

is there ANY way to execute aws-cli inside AWS Lambda? It doesn't seem to be pre-installed. (I've checked with "which aws" via Node.js child-process, and it didn't exist.)

like image 454
Hirofumi Okino Avatar asked Nov 04 '15 04:11

Hirofumi Okino


People also ask

Can AWS Lambda call AWS CLI?

In general, when you want to use AWS CLI in Lambda, it's best to call AWS APIs directly by using the appropriate SDK from your function's code. But there's one specific use case that is easier to do with the AWS CLI than API: aws s3 sync . This post will show how to enable AWS CLI in the Lambda execution environment.

What do you need to invoke your Lambda function using AWS CLI?

To invoke a lambda function synchronously, use the invoke command, passing it the function name, the payload and the output filename as parameters. Copied! If you're on Windows , escape the double quotes of the --payload parameter, e.g. '{\"name\": \"John Smith\"}' .

Why do we use the AWS CLI for the Lambda function?

The AWS CLI uses the AWS SDK for Python (Boto) to interact with the Lambda API. You can use it to learn about the API, and apply that knowledge in building applications that use Lambda with the AWS SDK. In this tutorial, you manage and invoke Lambda functions with the AWS CLI.

Can I console log in Lambda?

Using the CloudWatch consoleYou can use the Amazon CloudWatch console to view logs for all Lambda function invocations. Open the Log groups page on the CloudWatch console. Choose the log group for your function (/aws/lambda/ your-function-name ). Choose a log stream.


1 Answers

Now we can use Layers inside Lambda. Bash layer with aws-cli is available at https://github.com/gkrizek/bash-lambda-layer

handler () {     set -e      # Event Data is sent as the first parameter     EVENT_DATA=$1      # This is the Event Data     echo $EVENT_DATA      # Example of command usage     EVENT_JSON=$(echo $EVENT_DATA | jq .)      # Example of AWS command that's output will show up in CloudWatch Logs     aws s3 ls      # This is the return value because it's being sent to stderr (>&2)     echo "{\"success\": true}" >&2 } 
like image 112
Jai Avatar answered Sep 19 '22 15:09

Jai