Skip to content

Latest commit

 

History

History
98 lines (64 loc) · 3.16 KB

File metadata and controls

98 lines (64 loc) · 3.16 KB

Remote Development

Overview

The following is an exploration into provisioning and configured remote development environments to extend local environments.

Ideally, SSM Sessions will be used by way of SSH, which will require a key to be established.

After establishing SSH Key, choose an EnvironmentType to deploy.

SSH key setup and SSM

On local host:

ssh-keygen -b 4096 -C 'Dev SSH user' -t rsa -f ~/.ssh/id_rsa-remotedev
chmod 400 ~/.ssh/id_rsa-remotedev.pub

Setup AWS Session Manager Plugin for AWS CLI

Environment Types

EC2 SpotOne

References (EC2 SpotOne)

Setup (EC2 SpotOne)

Deploy resources

npm install
cdk deloy --context type=spotone

Configure SSH Authorized Key on EC2.

pubkey="$HOME/.ssh/id_rsa-remotedev.pub"
instanceId=$(aws ec2 describe-instances --filters 'Name=instance-state-name,Values=running' 'Name=tag:Name,Values=Ec2RemoteDevelopmentStack*' --output text --query 'Reservations[*].Instances[*].InstanceId')
az=$(aws ec2 describe-instances --filters 'Name=instance-state-name,Values=running' 'Name=tag:Name,Values=Ec2RemoteDevelopmentStack*' --output text --query 'Reservations[*].Instances[*].Placement.AvailabilityZone')

echo "Copying key to $instanceId"
aws ec2-instance-connect send-ssh-public-key --instance-id ${instanceId} --instance-os-user ec2-user \
--ssh-public-key file://${pubkey} --availability-zone ${az}

echo "Updating SSH Config"
echo -e "\nHost Spotone-$instanceId\n  IdentityFile $pubkey\n  User ec2-user\n  HostName $instanceId\n  ProxyCommand sh -c \"~/.ssh/ssm-proxy.sh %h %p\"" >> ~/.ssh/config

Cleanup (EC2 SpotOne)

cdk destroy --context type=spotone

Cloud9

References (Cloud9)

Setup (Cloud9)

npm install
cdk deploy --context type=cloud9

Usage (Cloud9)

Configure SSH Authorized Key on the Cloud9 EC2.

pubkey="$HOME/.ssh/id_rsa-remotedev.pub"
instanceId=$(aws ec2 describe-instances --filters 'Name=instance-state-name,Values=running' 'Name=tag:Name,Values=aws-cloud9-RemoteDevelopment*' --output text --query 'Reservations[*].Instances[*].InstanceId')
az=$(aws ec2 describe-instances --filters 'Name=instance-state-name,Values=running' 'Name=tag:Name,Values=aws-cloud9-RemoteDevelopment*' --output text --query 'Reservations[*].Instances[*].Placement.AvailabilityZone')

echo "Copying key to instance"
aws ec2-instance-connect send-ssh-public-key --instance-id ${instanceId} --instance-os-user ec2-user \
--ssh-public-key file://${pubkey} --availability-zone ${az}

echo "Updating SSH config"
echo -e "\nHost Cloud9-$instanceId\n  IdentityFile $pubkey\n  User ec2-user\n  HostName $instanceId\n  ProxyCommand sh -c \"~/.ssh/ssm-proxy.sh %h %p\"" >> ~/.ssh/config

Cleanup (Cloud9)

cdk destroy --context type=cloud9