Open the Visual Studio Code in your PC
Remote SSH
, select Remote - SSH and Remote - SSH: Editing Configuration Files
After the installation is complete, open Command Palette with Ctrl + Shift + P
Remote-SSH: Add New SSH Host
.cdk-workspace-ec2
.
The configuration of SSH Host will have the format like below
Host cdk-workspace
HostName x.x.x.x
User ec2-user
IdentityFile D:\path\to\private-key.pem
We’ll connect to the host which we’ve just added
Remote-SSH: Connect Current Windows to Host
cdk-workspace
Linux
Continue
After a few seconds, the connection is established successfully. Now you can open EC2’s directories in your VSCode
We’ll attach IAM Role to EC2 Instance, back to EC2 console, in Actions
CDK-Role
which you created before
sudo yum -y install jq gettext bash-completion moreutils
python 3.9
and pip
Firstly, we need to install these binaries to support python3.9
sudo yum install gcc openssl-devel bzip2-devel libffi-devel
Enter /opt
directory and get python3.9
compress file
cd /opt
wget https://www.python.org/ftp/python/3.9.16/Python-3.9.16.tgz
sudo tar xzf Python-3.9.16.tgz
Enter Python-3.9.16
directory and extract the downloaded file, and run configure
cd Python-3.9.16
sudo ./configure --enable-optimizations
sudo make altinstall
AWS CDK needs versions of python >= 3.8
pip install cfn-lint
And check the successful installation of cfn-lint using the following command:
cfn-lint --version
Before we can get metadata of EC2, we need to modify the instance metadata options
Make sure we can get the EC2 instance’s metadata
Set up environment variables
export ACCOUNT_ID=$(aws sts get-caller-identity --output text --query Account)
export AWS_REGION=$(curl -s 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))
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}
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
nvm install 20
node -v
npm -v
npm install -g aws-cdk
aws sts get-caller-identity --query Arn | grep CDK-Role -q && echo "IAM role valid" || echo "IAM role NOT valid"