demo / network-computer
Public
Copy of github.com/askrobots/network-computer (MIT): a desk you reach from anything. The original lives on GitHub.
GitStable demo
README: say this is a copy and where the original is
cde82c2
13 hours, 36 minutes ago
History
create-aws.sh · 2.3 KB · 44 lines
| 1 | #!/bin/sh |
| 2 | # Create an EC2 instance and provision it. |
| 3 | # Needs: awscli v2 configured (aws configure). |
| 4 | # Default region us-east-2 (Ohio, ~25-30ms from Houston, simplest). |
| 5 | # For the Houston Local Zone (single-digit ms) see the notes in infra/README.md. |
| 6 | # Usage: infra/create-aws.sh [name] [region] [type] |
| 7 | set -e |
| 8 | NAME=${1:-nc-ohio}; REGION=${2:-us-east-2}; TYPE=${3:-t3.medium} |
| 9 | DIR=$(dirname "$0") |
| 10 | command -v aws >/dev/null || { echo "install awscli: brew install awscli && aws configure"; exit 1; } |
| 11 | |
| 12 | echo "resolving latest Ubuntu 24.04 AMI in $REGION..." |
| 13 | AMI=$(aws ec2 describe-images --region "$REGION" --owners 099720109477 \ |
| 14 | --filters "Name=name,Values=ubuntu/images/hvm-ssd-gp3/ubuntu-noble-24.04-amd64-server-*" \ |
| 15 | --query 'sort_by(Images,&CreationDate)[-1].ImageId' --output text) |
| 16 | [ "$AMI" != None ] || { echo "no Ubuntu 24.04 AMI found"; exit 1; } |
| 17 | |
| 18 | # import the local SSH key |
| 19 | KEYNAME=nc-$(hostname -s) |
| 20 | aws ec2 import-key-pair --region "$REGION" --key-name "$KEYNAME" \ |
| 21 | --public-key-material "fileb://$HOME/.ssh/id_ed25519.pub" 2>/dev/null || true |
| 22 | |
| 23 | # security group with the ports the host needs |
| 24 | SG=$(aws ec2 create-security-group --region "$REGION" --group-name nc-$NAME \ |
| 25 | --description "network-computer" --query GroupId --output text 2>/dev/null || \ |
| 26 | aws ec2 describe-security-groups --region "$REGION" --group-names nc-$NAME --query 'SecurityGroups[0].GroupId' --output text) |
| 27 | for r in "tcp 22" "tcp 8765" "udp 3478" "udp 49152-65535"; do |
| 28 | set -- $r |
| 29 | aws ec2 authorize-security-group-ingress --region "$REGION" --group-id "$SG" \ |
| 30 | --ip-permissions "IpProtocol=$1,FromPort=${2%-*},ToPort=${2#*-},IpRanges=[{CidrIp=0.0.0.0/0}]" 2>/dev/null || true |
| 31 | done |
| 32 | |
| 33 | echo "launching $TYPE from $AMI..." |
| 34 | IID=$(aws ec2 run-instances --region "$REGION" --image-id "$AMI" --instance-type "$TYPE" \ |
| 35 | --key-name "$KEYNAME" --security-group-ids "$SG" \ |
| 36 | --block-device-mappings 'DeviceName=/dev/sda1,Ebs={VolumeSize=30}' \ |
| 37 | --tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=$NAME}]" \ |
| 38 | --query 'Instances[0].InstanceId' --output text) |
| 39 | echo "instance $IID, waiting for public ip..." |
| 40 | aws ec2 wait instance-running --region "$REGION" --instance-ids "$IID" |
| 41 | IP=$(aws ec2 describe-instances --region "$REGION" --instance-ids "$IID" \ |
| 42 | --query 'Reservations[0].Instances[0].PublicIpAddress' --output text) |
| 43 | echo "ip: $IP" |
| 44 | sh "$DIR/provision-host.sh" "$IP" "$NAME" ubuntu |