-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate-ec2.sh
39 lines (30 loc) · 1.24 KB
/
create-ec2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
if [ -z "$1" ]; then
echo -e "\e[31mInput machine name is needed\e[0m"
fi
COMPONENT=$1
HOSTED_ZONE_ID="Z03359161XEIHWG682X1"
createEc2(){
PRIVATE_IP=$(aws ec2 run-instances \
--image-id ${AMI_ID} \
--security-group-ids ${SG_ID} \
--instance-type t3.micro \
--tag-specifications "ResourceType=instance,Tags=[{Key=Name,Value=${COMPONENT}}]" \
--instance-market-options "MarketType=spot,SpotOptions={SpotInstanceType=persistent,InstanceInterruptionBehavior=stop}" \
|jq '.Instances[].PrivateIpAddress' | sed -e 's/"//g')
sed -e "s/COMPONENT/${COMPONENT}/" -e "s/IPADDRESS/${PRIVATE_IP}/" route53.json > /tmp/route53.json
aws route53 change-resource-record-sets --hosted-zone-id ${HOSTED_ZONE_ID} --change-batch file:///tmp/route53.json
}
AMI_ID=$(aws ec2 describe-images --filters "Name=name,Values=Centos-7-DevOps-Practice"|jq '.Images[].ImageId'|sed -e 's/"//g')
echo ${AMI_ID}
SG_ID=$(aws ec2 describe-security-groups --filters "Name=group-name,Values=allow-all-sg"|jq '.SecurityGroups[].GroupId'|sed -e 's/"//g')
echo ${SG_ID}
if [ "$1" == "all" ]; then
for component in cart catalogue frontend redis mysql mongodb payment rabbitmq shipping user dispatch
do
COMPONENT=${component}
createEc2
done
else
createEc2
fi