首页 > 解决方案 > 为 UserData 创建 CloudFormation 堆栈失败

问题描述

我创建了一个 CloudFormation 堆栈,并将旧 VPC Id 实施到新 VPC Id。但它正在使用 UserData Old VPC Id。我们正在切换到新的 VPC id 并执行 CFT 堆栈仍然低于问题, 2021-08-20 01:09:32 UTC+0530 MasterNodeWaitCondition CREATE_FAILED WaitCondition 收到失败消息:“配置失败。” 唯一 ID:i-072e5282d5854d33f

CloudFormation 堆栈用户数据下方:

 UserData:
    Fn::Base64:
      Fn::Sub:
        - |-
          <script>
          powershell -NoLogo -NonInteractive -ExecutionPolicy Bypass -Command "& { New-Item -Path C:\temp\run-before-aic.txt -Force -Type File -Value (Get-Date) }"
          powershell -NoLogo -NonInteractive -ExecutionPolicy Bypass -File C:\ProgramData\Sabre\aic-script.ps1
          powershell -NoLogo -NonInteractive -ExecutionPolicy Bypass -Command "& {New-Item -Path C:\temp\run-after-aic.txt -Force -Type File -Value (Get-Date) }"
          powershell -NoLogo -NonInteractive -ExecutionPolicy Bypass -Command "& { Set-Item -Path WSMan:\localhost\Client\TrustedHosts -Value '*' -Force }"
          netsh winhttp set proxy proxy-server="${ProxyDomain}:${ProxyPort}" bypass-list="localhost;169.254.169.254;cloudformation.us-west-2.amazonaws.com;ec2.us-west-2.amazonaws.com;ec2messages.us-west-2.amazonaws.com;kms.us-west-2.amazonaws.com;logs.us-west-2.amazonaws.com;monitoring.us-west-2.amazonaws.com;ssm.us-west-2.amazonaws.com;ssmmessages.us-west-2.amazonaws.com;10.*.*.*"
          cfn-init.exe -v -c config -r renderingserver1 -s ${AWS::StackName} --region ${AWS::Region} --http-proxy=http://${ProxyDomain}:${ProxyPort} --https-proxy=http://${ProxyDomain}:${ProxyPort}
          cfn-signal.exe -e %ERRORLEVEL% ${MasterNodeWaitHandle} -d "Done by me" --stack ${AWS::StackName} --region ${AWS::Region} --http-proxy=http://${ProxyDomain}:${ProxyPort} --https-proxy=http://${ProxyDomain}:${ProxyPort}
          <powershell>
          $AWS_AVAIL_ZONE=Get-EC2InstanceMetadata -Category AvailabilityZone
          $AWS_REGION=$AWS_AVAIL_ZONE.Substring(0,$AWS_AVAIL_ZONE.length-1)
          $AWS_INSTANCE_ID=Get-EC2InstanceMetadata -Category instanceId
          $ROOT_VOLUME_IDS=((Get-EC2Instance -Region $AWS_REGION -InstanceId $AWS_INSTANCE_ID).Instances.BlockDeviceMappings | where-object DeviceName -match '/dev/sda1').Ebs.VolumeId
          $Tags = @( @{key="Name";value="${RootEBSName}"},
                    @{key="Environment";value="dev"},
                    @{key="TechnicalService";value="${TechnicalService}"},
                    @{key="BusinessUnit";value="${BusinessUnit}"},
                    @{key="Customer";value="6H"},
                    @{key="AppIdentifier";value="${AppIdentifier}"},
                    @{key="ContactEmail";value="${ContactEmail}"},
                    @{key="Owner";value="${Owner}"}
                    @{key="BusinessService";value="${BusinessService}"} )
          New-EC2Tag -Resource $ROOT_VOLUME_IDS -Region $AWS_REGION -Tags $Tags
          </powershell>
          </script><persist>true</persist>
        - Owner:
            Ref: Owner
          BusinessService:
            Ref: BusinessService
          ProxyDomain:
            Fn::ImportValue:
              Fn::Sub: ${BusinessUnit}-dev-ss${ProxyVpcIdentifier}-proxy-domain
          BusinessUnit:
            Ref: BusinessUnit
          TechnicalService:
            Ref: TechnicalService
          ContactEmail:
            Ref: ContactEmail
          MasterNodeWaitHandle:
            Fn::Base64:
              Ref: MasterNodeWaitHandle
          RootEBSName:
            Fn::Join:
              - "-"
              - - ebs
                - Ref: BusinessUnit
                - 6H-dev-renderingserver1-Volume
          ProxyPort:
            Fn::ImportValue:
              Fn::Sub: ${BusinessUnit}-dev-ss${ProxyVpcIdentifier}-proxy-port
          AppIdentifier:
            Ref: AppIdentifier

使用旧 VPC Id 的 CFT 堆栈用户数据上方。请帮助使用powershell脚本对用户数据进行任何更改???

标签: amazon-web-servicesamazon-cloudformation

解决方案


推荐阅读