Search code examples
amazon-web-servicesaws-lambdaaws-cliaws-sdk-nodejs

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.)


Solution

  • 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
    }