Last active
February 5, 2024 19:37
-
-
Save ludflu/5f825c2c0f867fac2f9a640fa8e1fe78 to your computer and use it in GitHub Desktop.
script for setting airflow variables in AWS MWAA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# as described here: https://blog.beachgeek.co.uk/working-with-parameters-and-variables-in-amazon-managed-workflows-for-apache-airflow/ | |
[ $# -eq 0 ] && echo "Usage: $0 MWAA environment name " && exit | |
if [[ $2 == "" ]]; then | |
dag="variables list" | |
elif [ $2 == "get" ] || [ $2 == "delete" ] || [ $2 == "set" ]; then | |
dag="variables $2 $3 $4 $5" | |
else | |
echo "Not a valid command" | |
exit 1 | |
fi | |
CLI_JSON=$(aws mwaa --region $AWS_REGION create-cli-token --name $1) \ | |
&& CLI_TOKEN=$(echo $CLI_JSON | jq -r '.CliToken') \ | |
&& WEB_SERVER_HOSTNAME=$(echo $CLI_JSON | jq -r '.WebServerHostname') \ | |
&& CLI_RESULTS=$(curl --request POST "https://$WEB_SERVER_HOSTNAME/aws_mwaa/cli" \ | |
--header "Authorization: Bearer $CLI_TOKEN" \ | |
--header "Content-Type: text/plain" \ | |
--data-raw "$dag" ) \ | |
&& echo "Output:" \ | |
&& echo $CLI_RESULTS | jq -r '.stdout' | base64 --decode \ | |
&& echo "Errors:" \ | |
&& echo $CLI_RESULTS | jq -r '.stderr' | base64 --decode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment