#!/usr/bin/env bash # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: MIT-0 BIN_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) source $BIN_DIR/lib/bashFunctions readArgsIntoVars $* ROOT_DIR=$BIN_DIR/.. SAMPLES_DIR=$ROOT_DIR/samples BUILD_DIR=$ROOT_DIR/build CFN_BUILD_DIR=$BUILD_DIR/cfn mkdir -p $CFN_BUILD_DIR # Go through all the sample code folders for sampleDir in $SAMPLES_DIR/*/ ; do echo "$sampleDir" dashboard=$(cat $sampleDir/dashboard.json | sed 's/^/ /') permissions=$(cat $sampleDir/permissions.yaml | sed 's/^/ /') tags=$(cat $sampleDir/tags | sed 's/^/ /') # Go through each code file (*.js and *.py supported currently) codePaths="$sampleDir/*.??" for codePath in $codePaths; do code=$(cat $codePath | sed 's/^/ /') codeFirstLine="${code%%$'\n'*}" description="${codeFirstLine# *[^ ]* }" codeFilename=$(basename $codePath) extension="${codeFilename##*.}" functionName="${codeFilename%.*}-${extension}" functionName="$(tr '[:lower:]' '[:upper:]' <<< ${functionName:0:1})${functionName:1}" # capitalize functionName="customWidget${functionName}" if [ $extension == 'js' ]; then handler="index.handler" runtime="nodejs16.x" else handler="index.lambda_handler" runtime="python3.7" # python 3.8 doesn't suport inline zipfile yet fi # Create CloudFormation template cfnPath=$CFN_BUILD_DIR/$functionName.yaml echo ... creating $cfnPath cat > $cfnPath < $dashboard EOF done done