这是您正在寻找的 JSON 的有效格式
[
{
"Name": "Account Summary",
"Value": "/some/values/to/be/there"
},
{
"Name": "Account Investment",
"Value": "/some/other/values/here"
}
]
你的循环看起来像这样:
import json
ssm=[
{
"Name": "Account Summary",
"Value": "/some/values/to/be/there"
},
{
"Name": "Account Investment",
"Value": "/some/other/values/here"
}
]
for i in ssm:
print(f"aws ssm put-parameter --name \"{i.get('Name')}\" --type \"String\" --value \"{i.get('Value')}\"")
输出看起来像这样:
aws ssm put-parameter --name "Account Summary" --type "String" --value "/some/values/to/be/there"
aws ssm put-parameter --name "Account Investment" --type "String" --value "/some/other/values/here"
我不建议这样使用 AWS!这可能非常容易出错并且会带走很多功能,因为您需要将其作为子命令运行
您应该使用 AWS 提供的boto3 Python SDK 来处理这些事情。这是在脚本上访问 AWS 资源的推荐方式。
这是来自相同文档的示例代码片段put-parameter:
response = client.put_parameter(
Name='string',
Description='string',
Value='string',
Type='String'|'StringList'|'SecureString',
KeyId='string',
Overwrite=True|False,
AllowedPattern='string',
Tags=[
{
'Key': 'string',
'Value': 'string'
},
],
Tier='Standard'|'Advanced'|'Intelligent-Tiering',
Policies='string',
DataType='string'
)
如您所见,它具有更多功能,您可以更有效地检查响应,因为这会引发可以在脚本上检查的实际 Python 异常