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.)
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.
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\"}' .
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.
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.
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 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With