Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save anniethiessen/b73754d257b63aa401895883f34cd160 to your computer and use it in GitHub Desktop.

Select an option

Save anniethiessen/b73754d257b63aa401895883f34cd160 to your computer and use it in GitHub Desktop.
Script file to upload AWS Step Functions state machine.
#!/usr/bin/env bash
: '
Script file to upload AWS step functions state machine.
Ensure AWS is installed and configured,
define script variables, then execute script.
Accepts -v (verbose output) and -q (quiet output) arguments.
Prerequisites:
- aws-cli 1.29.62 -> https://pypi.org/project/awscli/
Script Variables:
- CONDA_ENV: The conda environment that has required packages installed.
Optional, if current environment has them installed.
- STATE_MACHINE_FILE_NAME: Name of upload file.
Required, no default.
- ARCHIVE_S3_BUCKET: S3 bucket to which archive files will be uploaded. Bucket must pre-exist.
Required, no default.
- ARCHIVE_S3_PREFIX: S3 bucket prefix to which the archive file should be uploaded.
Optional, defaults to "state_machines".
- ARCHIVE_FILE_NAME: File name the archive file should be given (should have a json extension).
Optional, defaults to "state-machine.json".
Usage Example:
CONDA_ENV=xxx
ARCHIVE_S3_BUCKET=xxx
wget -cO - "<this_file_url>" > "temp.sh"
chmod +x "temp.sh"
source "temp.sh" "$@"
rm -rf "temp.sh"
'
#--------------------------------------------
#------------------ CONSTANTS ---------------
#--------------------------------------------
CONDA_ENV="${CONDA_ENV}"
STATE_MACHINE_FILE_NAME="${STATE_MACHINE_FILE_NAME}"
ARCHIVE_S3_BUCKET="${ARCHIVE_S3_BUCKET}"
ARCHIVE_S3_PREFIX="${ARCHIVE_S3_PREFIX:-state_machines}"
ARCHIVE_FILE_NAME="${ARCHIVE_FILE_NAME:-state-machine.json}"
#------- DO NOT EDIT BELOW THIS LINE --------
FORMAT_SCRIPT_URL="https://gist.githubusercontent.com/anniethiessen/efb6bc0e52ccfc8b330aa41364b53e97/raw/0012edc1f009a36d196f03f09fda68e70691860b/shell_script_essentials.sh"
FORMAT_SCRIPT_NAME="shell_script_essentials.sh"
#--------------------------------------------
#--------------- FUNCTIONS ------------------
#--------------------------------------------
function run_format_script {
wget -cO - ${FORMAT_SCRIPT_URL} > ${FORMAT_SCRIPT_NAME}
chmod +x ${FORMAT_SCRIPT_NAME}
source ${FORMAT_SCRIPT_NAME} "$@"
rm -rf ${FORMAT_SCRIPT_NAME}
}
function upload () {
aws s3 cp \
"${STATE_MACHINE_FILE_NAME}" \
"s3://${ARCHIVE_S3_BUCKET}/${ARCHIVE_S3_PREFIX}/${ARCHIVE_FILE_NAME}" \
&> ${OUTPUT}
local retval=$?
if [[ ${retval} -eq 0 ]]; then
output_success_message "Archive uploaded to S3."
else
output_error_message "Archive upload to S3 error." ${PROMPT_VERBOSE}
fi
}
#--------------------------------------------
#------------------ MAIN --------------------
#--------------------------------------------
run_format_script "$@"
if [ -n "${CONDA_ENV}" ]; then
eval "$(conda shell.bash hook)"
conda activate ${CONDA_ENV}
output_success_message "Conda environment activated."
PYTHON_VERSION=$( python --version 2>&1 )
AWSCLI_VERSION=$( aws --version 2>&1 )
output_info_message "Using ${PYTHON_VERSION} and ${AWSCLI_VERSION}"
fi
output_header_message "----------------------------------------"
output_header_message "[1/1] UPLOAD"
output_header_message "uploading archive to S3 ..."
output_header_message "----------------------------------------"
upload
@anniethiessen
Copy link
Author

TODO:

@anniethiessen
Copy link
Author

anniethiessen commented Apr 28, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment