ROLE_NAME=role/deployment-role SESSION_NAME=${STAGE}-Deploy echo Assuming role ${ROLE_NAME} in account ${CROSS_ACCOUNT_ID} with session name ${SESSION_NAME} if [[ "${CROSS_ACCOUNT_ID}" == "" ]]; then >&2 echo Error: CROSS_ACCOUNT_ID must be set. Assuming cross account role has failed! exit 1 else IMPERSONATION=$(aws sts assume-role --role-arn "arn:aws:iam::${CROSS_ACCOUNT_ID}:${ROLE_NAME}" --role-session-name ${SESSION_NAME} --output text | tail -1) export AWS_ACCESS_KEY_ID=$(echo $IMPERSONATION | awk '{print $2}') export AWS_SECRET_ACCESS_KEY=$(echo $IMPERSONATION | awk '{print $4}') export AWS_SESSION_TOKEN=$(echo $IMPERSONATION | awk '{print $5}') fi