Skip to content

Commit

Permalink
Fixing empty accoubt id in locations
Browse files Browse the repository at this point in the history
  • Loading branch information
patduin committed Oct 2, 2023
1 parent 67e01f2 commit 6be5f19
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [3.0.15] - 2023-10-02
### Fixed
- Safeguard AWS account id call to prevent incorrect DB locations.

## [3.0.14] - 2023-08-11
### Changed
- Upgrade Maven version from `3.9.3` to `3.9.4` as the older version no longer supported.(https://dlcdn.apache.org/maven/maven-3/)
Expand Down
30 changes: 17 additions & 13 deletions files/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,23 @@ if [ -z $EXTERNAL_DATABASE ] && [ "$HIVE_METASTORE_ACCESS_MODE" = "readwrite" ];
HIVE_APIARY_DB_NAMES="${HIVE_APIARY_DB_NAMES},${APIARY_SYSTEM_SCHEMA:-apiary_system}"

AWS_ACCOUNT=`aws sts get-caller-identity|jq -r .Account`
for HIVE_DB in `echo ${HIVE_APIARY_DB_NAMES}|tr "," "\n"`
do
echo "creating hive database $HIVE_DB"
DB_ID=`echo "select MAX(DB_ID)+1 from DBS"|mysql $MYSQL_OPTIONS`
BUCKET_NAME=$(echo "${INSTANCE_NAME}-${AWS_ACCOUNT}-${AWS_REGION}-${HIVE_DB}"|tr "_" "-")
echo "insert into DBS(DB_ID,DB_LOCATION_URI,NAME,OWNER_NAME,OWNER_TYPE) values(\"$DB_ID\",\"s3://${BUCKET_NAME}/\",\"${HIVE_DB}\",\"root\",\"USER\") on duplicate key update DB_LOCATION_URI=\"s3://${BUCKET_NAME}/\";"|mysql $MYSQL_OPTIONS
#create glue database
if [ ! -z $ENABLE_GLUESYNC ]; then
echo "creating glue database $HIVE_DB"
aws --region=${AWS_REGION} glue create-database --database-input Name=${GLUE_PREFIX}${HIVE_DB},LocationUri=s3://${BUCKET_NAME}/ &> /dev/null
aws --region=${AWS_REGION} glue update-database --name=${GLUE_PREFIX}${HIVE_DB} --database-input "Name=${GLUE_PREFIX}${HIVE_DB},LocationUri=s3://${BUCKET_NAME}/,Description=Managed by ${INSTANCE_NAME} datalake."
fi
done
if [[ -n $AWS_ACCOUNT ]]; then
for HIVE_DB in `echo ${HIVE_APIARY_DB_NAMES}|tr "," "\n"`
do
echo "creating hive database $HIVE_DB"
DB_ID=`echo "select MAX(DB_ID)+1 from DBS"|mysql $MYSQL_OPTIONS`
BUCKET_NAME=$(echo "${INSTANCE_NAME}-${AWS_ACCOUNT}-${AWS_REGION}-${HIVE_DB}"|tr "_" "-")
echo "insert into DBS(DB_ID,DB_LOCATION_URI,NAME,OWNER_NAME,OWNER_TYPE) values(\"$DB_ID\",\"s3://${BUCKET_NAME}/\",\"${HIVE_DB}\",\"root\",\"USER\") on duplicate key update DB_LOCATION_URI=\"s3://${BUCKET_NAME}/\";"|mysql $MYSQL_OPTIONS
#create glue database
if [ ! -z $ENABLE_GLUESYNC ]; then
echo "creating glue database $HIVE_DB"
aws --region=${AWS_REGION} glue create-database --database-input Name=${GLUE_PREFIX}${HIVE_DB},LocationUri=s3://${BUCKET_NAME}/ &> /dev/null
aws --region=${AWS_REGION} glue update-database --name=${GLUE_PREFIX}${HIVE_DB} --database-input "Name=${GLUE_PREFIX}${HIVE_DB},LocationUri=s3://${BUCKET_NAME}/,Description=Managed by ${INSTANCE_NAME} datalake."
fi
done
else
echo "Could not get AWS_ACCOUNT, skipping update of DB entries."
fi
fi
fi

Expand Down

0 comments on commit 6be5f19

Please sign in to comment.