Amazon web services 无法在AWS目标组上注册目标
我正在尝试使用powershell设置自动DNS部署。我编写了一个powershell脚本,该脚本创建TargetGroup,向TG注册实例,创建ALB并向其中添加侦听器。完成后,它将创建R53记录集并向ALB DNS创建A记录。 我在将实例注册到TargetGroup时遇到问题。 这是我对该部分的代码片段:Amazon web services 无法在AWS目标组上注册目标,amazon-web-services,powershell,aws-alb,Amazon Web Services,Powershell,Aws Alb,我正在尝试使用powershell设置自动DNS部署。我编写了一个powershell脚本,该脚本创建TargetGroup,向TG注册实例,创建ALB并向其中添加侦听器。完成后,它将创建R53记录集并向ALB DNS创建A记录。 我在将实例注册到TargetGroup时遇到问题。 这是我对该部分的代码片段: $searchFor1 =@( @{name = 'tag:Name'; values = $target1}) $searchFor2 =@( @{name = 'tag:Name';
$searchFor1 =@( @{name = 'tag:Name'; values = $target1})
$searchFor2 =@( @{name = 'tag:Name'; values = $target2})
$id1 = (Get-EC2Instance -Filter $searchFor1).Instances | select InstanceId
$id2 = (Get-EC2Instance -Filter $searchFor2).Instances | select InstanceId
# Create Target Group
$tg = New-ELB2TargetGroup -TargetType "instance" -HealthyThresholdCount 4 -Name $custname -Port $siteport -Protocol "HTTP" -UnhealthyThresholdCount 4 -VpcId $vpcid
Start-Sleep -s 120
$addid1 = New-Object Amazon.ElasticLoadBalancingV2.Model.TargetDescription
$addid2 = New-Object Amazon.ElasticLoadBalancingV2.Model.TargetDescription
$addid1.Id = $id1.InstanceId
$addid2.Id = $id2.InstanceId
$addid1.Port = $siteport
$addid2.Port = $siteport
$tgarn = (Get-ELB2TargetGroup -Name $custname).TargetGroupArn
Register-ELB2Target -TargetGroupArn $tgarn -Target @($addid1)
Register-ELB2Target -TargetGroupArn $tgarn -Target @($addid2)
它抛出以下错误:
Register-ELB2Target : An instance ID must be specified
At C:\scripts\Distinct-DNS-Deployment.ps1:107 char:1
+ Register-ELB2Target -TargetGroupArn $tgarn -Target @($addid1)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Amazon.PowerShe...LB2TargetCmdlet:RegisterELB2TargetCmdlet) [Register
-ELB2Target], InvalidOperationException
+ FullyQualifiedErrorId : Amazon.ElasticLoadBalancingV2.AmazonElasticLoadBalancingV2Exception,Amazon.PowerShell.Cm
dlets.ELB2.RegisterELB2TargetCmdlet
我查过类似的帖子。和相应的职位,到目前为止没有任何帮助。我想知道是否有人能告诉我我做错了什么
我试着一行一行地运行每一行,但恰好将实例注册到TargetGroup,只是脚本失败了。
实例是t2.micro,它们处于运行状态。根据-
Amazon.ElasticLoadBalancingV2.Model.TargetDescription是关于“关于目标的信息”——
这意味着,如果仔细查看属性,还应该分配一个实例id:
AvailabilityZone系统.字符串
Id系统.字符串
端口系统.Int32
实例搜索的结果可能是单输出,也可能不是单输出-您应该将它们保持在循环中,以便通过TargetDescription创建每个目标
$Instances = (Get-EC2Instance -Filter @{Name="tag:auto-delete";Value="no"}).instances |select instanceid
$theVpc = get-ec2vpc -VpcId vpc-4565e5c4
$name = "new-tg"
$port = "80"
$protocol = "HTTP"
$tg = New-ELB2TargetGroup -TargetType "instance" -HealthyThresholdCount 4 -Name $name -Port $port -Protocol "HTTP" -UnhealthyThresholdCount 4 -VpcId $theVpc.VpcId
$tgarn = (Get-ELB2TargetGroup -Name $name).TargetGroupArn
If($instances -ne $null){
foreach ($instance in $instances ){
$addid1 = New-Object Amazon.ElasticLoadBalancingV2.Model.TargetDescription
$addid1.Id = $Instance.instanceid
$addid1.Port = $port
Register-ELB2Target -TargetGroupArn $tgarn -Target @($addid1)
Remove-Variable addid1
}
}
else {
echo "There were no instances with the matching filter"
}
根据—
Amazon.ElasticLoadBalancingV2.Model.TargetDescription是关于“关于目标的信息”——
这意味着,如果仔细查看属性,还应该分配一个实例id:
AvailabilityZone系统.字符串
Id系统.字符串
端口系统.Int32
实例搜索的结果可能是单输出,也可能不是单输出-您应该将它们保持在循环中,以便通过TargetDescription创建每个目标
$Instances = (Get-EC2Instance -Filter @{Name="tag:auto-delete";Value="no"}).instances |select instanceid
$theVpc = get-ec2vpc -VpcId vpc-4565e5c4
$name = "new-tg"
$port = "80"
$protocol = "HTTP"
$tg = New-ELB2TargetGroup -TargetType "instance" -HealthyThresholdCount 4 -Name $name -Port $port -Protocol "HTTP" -UnhealthyThresholdCount 4 -VpcId $theVpc.VpcId
$tgarn = (Get-ELB2TargetGroup -Name $name).TargetGroupArn
If($instances -ne $null){
foreach ($instance in $instances ){
$addid1 = New-Object Amazon.ElasticLoadBalancingV2.Model.TargetDescription
$addid1.Id = $Instance.instanceid
$addid1.Port = $port
Register-ELB2Target -TargetGroupArn $tgarn -Target @($addid1)
Remove-Variable addid1
}
}
else {
echo "There were no instances with the matching filter"
}
您确定搜索实例时确实返回了一些内容:$addid1.Id=$id1.InstanceId您确定搜索实例时确实返回了一些内容:$addid1.Id=$id1.InstanceId您好,问题是如何查看目标。我有$target=$target.ToLower()。它返回的名称标记都是小写的,而实际的实例名称标记的第一个字符是大写的。$addid1.id因此返回空值。修正后,我可以注册目标。同样感谢KS的洞察力,我将尝试将其作为解决此问题的替代方法。您好,问题是如何看待目标。我有$target=$target.ToLower()。它返回的名称标记都是小写的,而实际的实例名称标记的第一个字符是大写的。$addid1.id因此返回空值。修正后,我可以注册目标。同样感谢KS的洞察力,我将尝试使用它作为解决此问题的替代方法。