[ASK CLI] Run specific command before deploy your Lambda

ASK CLI has hook to deploy / clone your skill. You can check exists hooks in the hooks/directory. Example hook […]

広告ここから
広告ここまで

目次

    ASK CLI has hook to deploy / clone your skill. You can check exists hooks in the hooks/directory.

    Example hook

    From: https://github.com/alexa/skill-sample-nodejs-trivia/blob/en-US/hooks/pre_deploy_hook.sh

    SKILL_NAME=$1
    DO_DEBUG=${2:-false}
    TARGET=${3:-"all"}
    
    if [ $DO_DEBUG == false ]
    then
        exec > /dev/null 2>&1
    fi
    
    install_dependencies() {
        npm install --prefix "$1" >/dev/null 2>&1 
        return $?
    }
    
    echo "###########################"
    echo "##### pre-deploy hook #####"
    echo "###########################"
    
    if [[ $TARGET == "all" || $TARGET == "lambda" ]]; then
        grep "sourceDir" ./skill.json | cut -d: -f2 |  sed 's/"//g' | sed 's/,//g' | while read -r SOURCE_DIR; do
            if install_dependencies $SOURCE_DIR; then
                echo "Codebase ($SOURCE_DIR) built successfully."
            else
                echo "There was a problem installing dependencies for ($SOURCE_DIR)."
                exit 1
            fi
        done
        echo "###########################"
    fi
    
    exit 0

    The hook is to run the npm installcommand before deploying your Lambda function. (The hook result and progress cannot see by default, you need to add --debugoptions.)

    Use case

    The most popular case is to build the TypeScript. You can run build by TypeScript by the following code.

    install_dependencies() {
        npm install --prefix "$1" >/dev/null 2>&1 
        npm run build --prefix "$1"
        return $?
    }

    More idea

    Of course we can run the Serverless Framework or SAM or CloudFormation.

    Let’s make a new hook for your Alexa development environment 🙂

    広告ここから
    広告ここまで

    Random posts

    Home
    Search
    Bookmark