我在Lambda中有一些代码,想使用Lambda Environment变量保护密码。
现在的代码如下:
command = ssm_client.send_command( \
InstanceIds=[InstanceId], \
DocumentName='AWS-RunPowerShellScript', \
Parameters={ \
"commands":[" \
$pass = ConvertTo-SecureString superPassword123 -AsPlainText -Force; \
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList kagarlickij\Admin,$pass; \
Remove-Computer -ComputerName $(hostname) -Credential $creds -Verbose -Restart -Force \
"]} )`
考虑到所有这些括号,如何将superPassword123
替换为os.environ['DomainPassword']
?
答案 0 :(得分:1)
您可以使用字符串格式传递密码(或python中的其他任何硬编码子字符串:
"commands":[" \
$pass = ConvertTo-SecureString {pw} -AsPlainText -Force; \
$creds = New-Object System.Management.Automation.PSCredential -ArgumentList kagarlickij\Admin,$pass; \
Remove-Computer -ComputerName $(hostname) -Credential $creds -Verbose -Restart -Force \
".format(pw = os.environ['DomainPassword'])