我正在CloudFormation的帮助下创建EC2 Windows实例。如果要连接到Windows实例,则必须进行through this steps。
其中一个步骤需要管理员用户名和密码。您可以在CLI上手动检查密码。但是我可以在CloudFormation堆栈中写管理员的用户名/密码t输出部分吗?
答案 0 :(得分:1)
您有几种合适的方法。
!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 ec2 --region ap-southeast-2 get-password-data --priv-launch-key secret.pem --instance-id i-123123124
答案 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?