mirror of https://github.com/OpenVidu/openvidu.git
openvidu-deployment: AWS - wait for the Elastic IP before deriving the domain
NewEIP was created with InstanceId, so the Elastic IP was attached only after the instance existed, racing with the boot scripts: the domain could be derived from whatever public IP the instance had at that moment (the subnet's ephemeral one, or none), and with no public IP there was no Internet access for apt-get, cfn-init or the installer either. In the CE single node, Pro single node and Pro elastic templates, NewEIP is now allocated on its own and attached by a separate NewEIPAssociation, so its address is known up front. UserData waits up to 10 minutes for the instance to have that address before doing anything else, and install.sh reads public-ipv4 instead of public-hostname (empty in VPCs without DNS hostnames). Assisted-by: claude-code - Anthropic - Claude Opus 5.5media-node-health
parent
3208097dd4
commit
b372409ccf
|
|
@ -706,8 +706,7 @@ Resources:
|
|||
|
||||
# Configure Domain
|
||||
if [[ "${DomainName}" == '' ]]; then
|
||||
PublicHostname=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/public-hostname)
|
||||
DOMAIN=$(echo "$PublicHostname" | cut -d'.' -f1 | sed 's/^ec2-//' | tr '-' '.')
|
||||
DOMAIN=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/public-ipv4)
|
||||
else
|
||||
DOMAIN=${DomainName}
|
||||
fi
|
||||
|
|
@ -1100,10 +1099,28 @@ Resources:
|
|||
- Key: Name
|
||||
Value: !Ref 'AWS::StackName'
|
||||
UserData:
|
||||
Fn::Base64: !Sub |
|
||||
Fn::Base64: !Sub
|
||||
- |
|
||||
#!/bin/bash -x
|
||||
set -eu -o pipefail
|
||||
|
||||
# Wait for the Elastic IP: CloudFormation associates it only after the instance
|
||||
# is created, and until then the instance may have another public IP (or none,
|
||||
# and no Internet access)
|
||||
TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
|
||||
CURRENT_PUBLIC_IP=""
|
||||
for _ in $(seq 1 120); do
|
||||
CURRENT_PUBLIC_IP=$(curl -sf -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/public-ipv4 || true)
|
||||
if [[ "$CURRENT_PUBLIC_IP" == "${ExpectedPublicIp}" ]]; then
|
||||
break
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
if [[ "$CURRENT_PUBLIC_IP" != "${ExpectedPublicIp}" ]]; then
|
||||
echo "[OpenVidu] Elastic IP ${ExpectedPublicIp} not attached after 10 minutes"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "DPkg::Lock::Timeout \"-1\";" > /etc/apt/apt.conf.d/99timeout
|
||||
|
||||
apt-get update && apt-get install -y \
|
||||
|
|
@ -1143,6 +1160,7 @@ Resources:
|
|||
|
||||
# sending the finish call
|
||||
cfn-signal -e $? --stack ${AWS::StackId} --resource WaitCondition --region ${AWS::Region}
|
||||
- ExpectedPublicIp: !If [PublicElasticIPPresent, !Ref PublicElasticIP, !Ref NewEIP]
|
||||
|
||||
BlockDeviceMappings:
|
||||
- DeviceName: /dev/sda1
|
||||
|
|
@ -1161,8 +1179,13 @@ Resources:
|
|||
NewEIP:
|
||||
Type: 'AWS::EC2::EIP'
|
||||
Condition: PublicElasticIPAbsent
|
||||
|
||||
NewEIPAssociation:
|
||||
Type: 'AWS::EC2::EIPAssociation'
|
||||
Condition: PublicElasticIPAbsent
|
||||
Properties:
|
||||
InstanceId: !Ref OpenviduServer
|
||||
AllocationId: !GetAtt NewEIP.AllocationId
|
||||
|
||||
IMDSv2LaunchTemplate:
|
||||
Type: AWS::EC2::LaunchTemplate
|
||||
|
|
|
|||
|
|
@ -1410,8 +1410,13 @@ Resources:
|
|||
NewEIP:
|
||||
Type: 'AWS::EC2::EIP'
|
||||
Condition: PublicElasticIPAbsent
|
||||
|
||||
NewEIPAssociation:
|
||||
Type: 'AWS::EC2::EIPAssociation'
|
||||
Condition: PublicElasticIPAbsent
|
||||
Properties:
|
||||
InstanceId: !Ref OpenViduMasterNode
|
||||
AllocationId: !GetAtt NewEIP.AllocationId
|
||||
|
||||
IMDSv2LaunchTemplateMasterNode:
|
||||
Type: AWS::EC2::LaunchTemplate
|
||||
|
|
@ -1469,8 +1474,7 @@ Resources:
|
|||
|
||||
# Configure Domain and other parameters
|
||||
if [[ "${DomainName}" == '' ]]; then
|
||||
PublicHostname=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/public-hostname)
|
||||
DOMAIN=$(echo "$PublicHostname" | cut -d'.' -f1 | sed 's/^ec2-//' | tr '-' '.')
|
||||
DOMAIN=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/public-ipv4)
|
||||
else
|
||||
DOMAIN=${DomainName}
|
||||
fi
|
||||
|
|
@ -1940,10 +1944,28 @@ Resources:
|
|||
- Key: Name
|
||||
Value: !Sub ${AWS::StackName} - OpenVidu Elastic - Master Node
|
||||
UserData:
|
||||
Fn::Base64: !Sub |
|
||||
Fn::Base64: !Sub
|
||||
- |
|
||||
#!/bin/bash
|
||||
set -eu -o pipefail
|
||||
|
||||
# Wait for the Elastic IP: CloudFormation associates it only after the instance
|
||||
# is created, and until then the instance may have another public IP (or none,
|
||||
# and no Internet access)
|
||||
TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
|
||||
CURRENT_PUBLIC_IP=""
|
||||
for _ in $(seq 1 120); do
|
||||
CURRENT_PUBLIC_IP=$(curl -sf -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/public-ipv4 || true)
|
||||
if [[ "$CURRENT_PUBLIC_IP" == "${ExpectedPublicIp}" ]]; then
|
||||
break
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
if [[ "$CURRENT_PUBLIC_IP" != "${ExpectedPublicIp}" ]]; then
|
||||
echo "[OpenVidu] Elastic IP ${ExpectedPublicIp} not attached after 10 minutes"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "DPkg::Lock::Timeout \"-1\";" > /etc/apt/apt.conf.d/99timeout
|
||||
|
||||
apt-get update && apt-get install -y \
|
||||
|
|
@ -2005,6 +2027,7 @@ Resources:
|
|||
|
||||
# sending the finish call
|
||||
cfn-signal -e $? --stack ${AWS::StackId} --resource WaitCondition --region ${AWS::Region}
|
||||
- ExpectedPublicIp: !If [PublicElasticIPPresent, !Ref PublicElasticIP, !Ref NewEIP]
|
||||
|
||||
BlockDeviceMappings:
|
||||
- DeviceName: /dev/sda1
|
||||
|
|
|
|||
|
|
@ -808,8 +808,7 @@ Resources:
|
|||
|
||||
# Configure Domain
|
||||
if [[ "${DomainName}" == '' ]]; then
|
||||
PublicHostname=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/public-hostname)
|
||||
DOMAIN=$(echo "$PublicHostname" | cut -d'.' -f1 | sed 's/^ec2-//' | tr '-' '.')
|
||||
DOMAIN=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/public-ipv4)
|
||||
else
|
||||
DOMAIN=${DomainName}
|
||||
fi
|
||||
|
|
@ -1217,10 +1216,28 @@ Resources:
|
|||
- Key: Name
|
||||
Value: !Ref 'AWS::StackName'
|
||||
UserData:
|
||||
Fn::Base64: !Sub |
|
||||
Fn::Base64: !Sub
|
||||
- |
|
||||
#!/bin/bash -x
|
||||
set -eu -o pipefail
|
||||
|
||||
# Wait for the Elastic IP: CloudFormation associates it only after the instance
|
||||
# is created, and until then the instance may have another public IP (or none,
|
||||
# and no Internet access)
|
||||
TOKEN=$(curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
|
||||
CURRENT_PUBLIC_IP=""
|
||||
for _ in $(seq 1 120); do
|
||||
CURRENT_PUBLIC_IP=$(curl -sf -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/public-ipv4 || true)
|
||||
if [[ "$CURRENT_PUBLIC_IP" == "${ExpectedPublicIp}" ]]; then
|
||||
break
|
||||
fi
|
||||
sleep 5
|
||||
done
|
||||
if [[ "$CURRENT_PUBLIC_IP" != "${ExpectedPublicIp}" ]]; then
|
||||
echo "[OpenVidu] Elastic IP ${ExpectedPublicIp} not attached after 10 minutes"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "DPkg::Lock::Timeout \"-1\";" > /etc/apt/apt.conf.d/99timeout
|
||||
|
||||
apt-get update && apt-get install -y \
|
||||
|
|
@ -1260,6 +1277,7 @@ Resources:
|
|||
|
||||
# sending the finish call
|
||||
cfn-signal -e $? --stack ${AWS::StackId} --resource WaitCondition --region ${AWS::Region}
|
||||
- ExpectedPublicIp: !If [PublicElasticIPPresent, !Ref PublicElasticIP, !Ref NewEIP]
|
||||
|
||||
BlockDeviceMappings:
|
||||
- DeviceName: /dev/sda1
|
||||
|
|
@ -1278,8 +1296,13 @@ Resources:
|
|||
NewEIP:
|
||||
Type: 'AWS::EC2::EIP'
|
||||
Condition: PublicElasticIPAbsent
|
||||
|
||||
NewEIPAssociation:
|
||||
Type: 'AWS::EC2::EIPAssociation'
|
||||
Condition: PublicElasticIPAbsent
|
||||
Properties:
|
||||
InstanceId: !Ref OpenviduServer
|
||||
AllocationId: !GetAtt NewEIP.AllocationId
|
||||
|
||||
IMDSv2LaunchTemplate:
|
||||
Type: AWS::EC2::LaunchTemplate
|
||||
|
|
|
|||
Loading…
Reference in New Issue