Update Workspace configuration

Update EC2 Workspace configuration

Because we have attached the IAM Role directly to the EC2 instance, the system will automatically use the permissions of this Role. We just need to reset the necessary environment variables.

  1. To ensure that no old credential information remains in the instance, we will delete the credentials file (if any) using the command below.
rm -vf ${HOME}/.aws/credentials

Update configure role

  1. Next we will configure the AWS CLI to use the current Region.
export ACCOUNT_ID=$(aws sts get-caller-identity --output text --query Account)
TOKEN=$(curl -sX PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
export AWS_REGION=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.region')
export AZS=($(aws ec2 describe-availability-zones --query 'AvailabilityZones[].ZoneName' --output text --region $AWS_REGION))

Update configure role

  1. Check if AWS_REGION has been set correctly to the current Region.
test -n "$AWS_REGION" && echo AWS_REGION is "$AWS_REGION" || echo AWS_REGION is not set

Update configure role

  1. Next we will save the configuration information to bash_profile
echo "export ACCOUNT_ID=${ACCOUNT_ID}" | tee -a ~/.bash_profile
echo "export AWS_REGION=${AWS_REGION}" | tee -a ~/.bash_profile
echo "export AZS=(${AZS[@]})" | tee -a ~/.bash_profile
aws configure set default.region ${AWS_REGION}
aws configure get default.region

Update configure role

  1. Check IAM Role
  • We will use the command to verify if the EC2 Workspace is using the correct IAM Role.
aws sts get-caller-identity --query Arn | grep eksworkshop-admin -q && echo "IAM role valid" || echo "IAM role NOT valid"

Update configure role