From faaddf31da96d88a7cea03a9ed3a446acc013d41 Mon Sep 17 00:00:00 2001 From: Ruchika Modi <106240341+ruchimo@users.noreply.github.com> Date: Mon, 8 Apr 2024 16:58:02 +0530 Subject: [PATCH] Fix python installation and update to support IMDSv2 --- content/capacity_providers/software.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/content/capacity_providers/software.md b/content/capacity_providers/software.md index 83ed188..92eaa11 100644 --- a/content/capacity_providers/software.md +++ b/content/capacity_providers/software.md @@ -10,11 +10,18 @@ In the Cloud9 workspace, run the following commands: ``` # Install prerequisite packages -sudo yum -y install jq nodejs python36 +sudo yum -y install jq nodejs python3 -# Setting environment variables required to communicate with AWS API's via the cli tools +# Setting environment variables required to communicate with AWS API's via the cli tools, execute either for IMDSv1 or IMDSv2 (based on your IMDS version) +# IMDSv1 echo "export AWS_DEFAULT_REGION=$(curl -s 169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region)" >> ~/.bashrc echo "export AWS_REGION=\$AWS_DEFAULT_REGION" >> ~/.bashrc echo "export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)" >> ~/.bashrc source ~/.bashrc -``` \ No newline at end of file + +# IMDSv2 +TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && REGION=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region) && echo "AWS_DEFAULT_REGION=$REGION" >> ~/.bashrc +echo "export AWS_REGION=\$AWS_DEFAULT_REGION" >> ~/.bashrc +echo "export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)" >> ~/.bashrc +source ~/.bashrc +```