Skip to content

Instantly share code, notes, and snippets.

@colemickens
Created November 2, 2020 20:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colemickens/3a3fda5ef739d27112b20ede76126a98 to your computer and use it in GitHub Desktop.
Save colemickens/3a3fda5ef739d27112b20ede76126a98 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -x
set -euo pipefail
# TODO: maybe we need to upload our own AMI or something?
REGION="us-west-2"
AMI_ID="ami-073449580ff8e82b5" #NixOS-20.03.2351.f8248ab6d9e-aarch64-linux
#AMI_ID="ami-053c71bfc2f2ae88d" # NixOS-20.09alpha417.a780c60f9f7-aarch64-linux
INSTANCE_TYPE="m6g.4xlarge"
INDEX="1"
vpc="$(aws ec2 create-vpc \
--cidr-block "10.${INDEX}.0.0/16" \
--region "${REGION}" | jq -r '.Vpc.VpcId')"
sub="$(aws ec2 create-subnet \
--vpc-id "${vpc}" \
--region "${REGION}" \
--cidr-block "10.${INDEX}.1.0/24" | jq -r '.Subnet.SubnetId')"
sg="$(aws ec2 create-security-group \
--description "${vpc}-ssh" \
--vpc-id "${vpc}" \
--group-name "${vpc}-ssh" \
--region "${REGION}" | jq -r '.GroupId')"
aws ec2 authorize-security-group-ingress \
--group-id "${sg}" \
--protocol tcp \
--port 22 \
--cidr 0.0.0.0/0 \
--region "${REGION}"
aws ec2 run-instances \
--image-id "${AMI_ID}" \
--count 1 \
--region "${REGION}" \
--subnet-id "${sub}" \
--security-group-id "${sg}" \
--instance-type "${INSTANCE_TYPE}" \
--block-device-mappings "[{\"DeviceName\": \"/dev/xvda\",\"Ebs\":{\"VolumeSize\":100,\"VolumeType\":\"gp2\"}}]" \
--key-name "colemickens" \
--associate-public-ip-address | jq
# add SG rule for tcp/22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment