61 lines
1.4 KiB
Bash
61 lines
1.4 KiB
Bash
#!/bin/bash
|
|
|
|
# VARIABLES
|
|
KEY_NAME="my-key"
|
|
SECURITY_GROUP="notes-app-sg"
|
|
INSTANCE_NAME="notes-app-vm"
|
|
AMI_ID="ami-0e872aee57663ae2d"
|
|
INSTANCE_TYPE="t2.micro"
|
|
REGION="eu-central-1"
|
|
|
|
# CREATE SECURITY GROUP
|
|
aws ec2 create-security-group \
|
|
--group-name $SECURITY_GROUP \
|
|
--description "Security group for Notes App" \
|
|
--region $REGION
|
|
|
|
# OPEN PORTS
|
|
aws ec2 authorize-security-group-ingress \
|
|
--group-name $SECURITY_GROUP \
|
|
--protocol tcp \
|
|
--port 22 \
|
|
--cidr 0.0.0.0/0 \
|
|
--region $REGION
|
|
|
|
aws ec2 authorize-security-group-ingress \
|
|
--group-name $SECURITY_GROUP \
|
|
--protocol tcp \
|
|
--port 80 \
|
|
--cidr 0.0.0.0/0 \
|
|
--region $REGION
|
|
|
|
aws ec2 authorize-security-group-ingress \
|
|
--group-name $SECURITY_GROUP \
|
|
--protocol tcp \
|
|
--port 443 \
|
|
--cidr 0.0.0.0/0 \
|
|
--region $REGION
|
|
|
|
aws ec2 authorize-security-group-ingress \
|
|
--group-name $SECURITY_GROUP \
|
|
--protocol tcp \
|
|
--port 8080 \
|
|
--cidr 0.0.0.0/0 \
|
|
--region $REGION
|
|
|
|
aws ec2 authorize-security-group-ingress \
|
|
--group-name $SECURITY_GROUP \
|
|
--protocol tcp \
|
|
--port 8081 \
|
|
--cidr 0.0.0.0/0 \
|
|
--region $REGION
|
|
|
|
# CREATE INSTANCE
|
|
aws ec2 run-instances \
|
|
--image-id $AMI_ID \
|
|
--count 1 \
|
|
--instance-type $INSTANCE_TYPE \
|
|
--key-name $KEY_NAME \
|
|
--security-groups $SECURITY_GROUP \
|
|
--tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=$INSTANCE_NAME}]" \
|
|
--region $REGION |