Skip to content

Instantly share code, notes, and snippets.

View YakDriver's full-sized avatar
🕳️
🌑

Dirk Avery YakDriver

🕳️
🌑
View GitHub Profile
@YakDriver
YakDriver / aws_profile_manager.sh
Created January 22, 2018 16:47
Manage an AWS profile instance given environment variables
# Given environment variables of INSTANCE_PROFILE and INSTANCE_ROLE, this will create the profile,
# swap out the role, remove the role, add the role to make sure at the end, INSTANCE_PROFILE contains
# one and only one role, INSTANCE_ROLE
if aws iam get-instance-profile --instance-profile-name "${INSTANCE_PROFILE}" ; then
echo "Profile already exists. Checking instance profile..."
OLD_ROLE="$(aws iam get-instance-profile --instance-profile-name $INSTANCE_PROFILE | ./jq.dms -r '.InstanceProfile.Roles[0].RoleName')"
if [ "${OLD_ROLE}" = "null" ] || [ -z "${OLD_ROLE}" ] ; then
OLD_ROLE=none
fi
if [ "${INSTANCE_ROLE}" = "${OLD_ROLE}" ] ; then