CloudFormation EC2 Windows管理员密码

时间:2019-01-23 14:20:15

标签: amazon-web-services amazon-ec2 amazon-cloudformation

我正在CloudFormation的帮助下创建EC2 Windows实例。如果要连接到Windows实例,则必须进行through this steps

其中一个步骤需要管理员用户名和密码。您可以在CLI上手动检查密码。但是我可以在CloudFormation堆栈中写管理员的用户名/密码t输出部分吗?

2 个答案:

答案 0 :(得分:1)

您有几种合适的方法。

  • 输入用于CloudFormation的用户名和密码的参数。使用NoEcho参数。然后,您可以在输出中执行!Ref AdminPassword,但这并不是一个好主意。

模板

Parameters:
  AdminPassword:
    Description: Admin Password
    Type: String
    NoEcho: true
    MinLength: 8
    MaxLength: 32
    ConstraintDescription: Must be at least 8 chars long

您还需要使用!Sub将其添加到用户数据中以替换字符串

<powershell>
cmd.exe /c net user /add admin ${AdminPassword}
cmd.exe /c net localgroup administrators admin /add
cmd.exe /c NET localgroup "Remote Desktop Users" admin /ADD
<powershell>
  • 您可以运行 aws cli
aws ec2 --region ap-southeast-2 get-password-data --priv-launch-key secret.pem --instance-id i-123123124
  • SSM参数也是一个不错的选择

答案 1 :(得分:0)

不确定是否有直接方法可以在CFN模板的输出部分中获取密码,但是您可以使用API​​调用lambda来调用getpassworddata https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_GetPasswordData.html

此链接说明了如何调用lambda函数以通过s3对象检索任何输出 Can AWS CloudFormation call the AWS API?