如何提供文件内容作为 aws cli 选项值
how to provide a file content as an aws cli option value
我正在尝试在我的 Linux Box 中借助 AWS CLI 创建一个 SFTP 用户。
下面是我在 bash 脚本中传递的 AWS CLI 命令(我的 ssh public 密钥在文件中,借助变量我将其传递到 AWS CLI 选项节)
customer_name_pub_value=$(cat /home/developer/naman/dir/$customer_name.pub)
aws transfer create-user --user-name $customer_name --home-directory script-test/power-archive-ireland/$customer_name/ --server-id s-aaabbbccc --ssh-public-key-body $customer_name_pub_value --tags 'Key=Product,Value="demo",Key=Environment,Value=dev,Key=Contact,Value="dev.user@domain.com",Key=Service,Value="sftp"' --role customer-sftp-role
以下是我在执行上述命令时遇到的错误:
[developer@dev-lin demo]$ aws transfer create-user --user-name $customer_name --home-directory script-test/power-archive-ireland/$customer_name/ --server-id s-aaabbbccc --ssh-public-key-body $customer_name_pub_value --tags 'Key=Product,Value="demo",Key=Environment,Value=dev,Key=Contact,Value="dev.user@domain.com",Key=Service,Value="sftp"' --role customer-sftp-role
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
Unknown options: developer@dev-lin.domain.com, XXXXXXXXXXAB3NzaC1yc2EAAAADAQABAAABAQCm2hI3Y33K1GVbdQV0lfkm/klZRJS7Kcz8+53e/BoIbVMFH0jqm1aejELDFgPnN7HvIZ/csYGzF/ssTx5lXVaHQh/qkYwfqQBg8WvXVB0Jmogj1hr6z5M8Qy/3oCx0fSmh6e/Ekfk8vHhiHQlGZV3o8a2AW5SkP8IH/OgT6Bq+SMuB+xtSciVBZqSLI0OgYtOZ0MyxBzfLau1Tyegu5lVFevZDVjecnIaS4l+v2VIQ/OgaZ40oAI3NuRZ2EdnLqEqFyLjasx4kcuwNzD5oaXAU6T9UsqKN2rVLMKrXXXXXXXXXXX
我在传递选项值时是否缺少某些 bash 语法!
2020 年 3 月 30 日更新
根据以下评论中的建议,我在命令中添加了 AWS ARN 角色,现在面临与以前不同的问题
代码:
customer_name='demo'
customer_name_pub_value=$(cat /home/developer/naman/dir/$customer_name.pub)
aws transfer create-user --user-name $customer_name --home-directory script-test/power-archive-ireland/$customer_name/ --server-id s-aaabbbccc --ssh-public-key-body "$customer_name_pub_value" --tags 'Key=Product,Value="demo",Key=Environment,Value=dev,Key=Contact,Value="dev.user@domain.com",Key=Service,Value="sftp"' --role "arn:aws:iam::8XXXXXXXXX2:role/customer-sftp-role"
错误
An error occurred (ValidationException) when calling the CreateUser operation: 1 validation error detected: Value 'script-test/power-archive-ireland/demo/' at 'homeDirectory' failed to satisfy constraint: Member must satisfy regular expression pattern: ^$|/.*
是的,对于最后一个错误,您应该将其作为对象列表提供:
--tags [{Key="Product", Value="demo"}, {Key="Environment", Value="dev"}, {Key="Contact", Value="dev.user@domain.com"}, {Key="Service", Value="sftp"
您可能需要将 "Key" 和 "Value" 放在引号中,甚至可能必须尝试 key:value 对(即 {"Product": "demo"} ), 但这应该是通用语法。
下面是最终运行的 CLI 命令:
变化
添加了 ROLE ARN(感谢@user1394 的建议)
通过在 --home-directory 选项之前放置 / 解决了最大的问题(糟糕的 AWS 文档 (https://docs.aws.amazon.com/cli/latest/reference/transfer/create-user.html) 及其过时的 RegEx ^$|/.*
)
将损坏的 CLI 转换为基于 JSON 的 CLI 以修复最终错误(并非所有标签都能够附加到旧命令中)
#!/bin/bash
customer_name='demo'
customer_name_pub_value=$(cat /home/developer/naman/dir/$customer_name.pub)
aws transfer create-user \
--user-name $customer_name \
--server-id s-aaabbbccc \
--role "arn:aws:iam::8XXXXXXXXX2:role/customer-sftp-role" \
--ssh-public-key-body "$customer_name_pub_value" \
--home-directory /script-test/power-archive-ireland/$customer_name \
--tags '[
{"Key": "Product", "Value": "demo"},
{"Key": "Environment", "Value": "dev"},
{"Key": "Contact", "Value": "dev.user@domain.com"},
{"Key": "Service", "Value": "sftp"}
]'
我正在尝试在我的 Linux Box 中借助 AWS CLI 创建一个 SFTP 用户。
下面是我在 bash 脚本中传递的 AWS CLI 命令(我的 ssh public 密钥在文件中,借助变量我将其传递到 AWS CLI 选项节)
customer_name_pub_value=$(cat /home/developer/naman/dir/$customer_name.pub)
aws transfer create-user --user-name $customer_name --home-directory script-test/power-archive-ireland/$customer_name/ --server-id s-aaabbbccc --ssh-public-key-body $customer_name_pub_value --tags 'Key=Product,Value="demo",Key=Environment,Value=dev,Key=Contact,Value="dev.user@domain.com",Key=Service,Value="sftp"' --role customer-sftp-role
以下是我在执行上述命令时遇到的错误:
[developer@dev-lin demo]$ aws transfer create-user --user-name $customer_name --home-directory script-test/power-archive-ireland/$customer_name/ --server-id s-aaabbbccc --ssh-public-key-body $customer_name_pub_value --tags 'Key=Product,Value="demo",Key=Environment,Value=dev,Key=Contact,Value="dev.user@domain.com",Key=Service,Value="sftp"' --role customer-sftp-role
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
Unknown options: developer@dev-lin.domain.com, XXXXXXXXXXAB3NzaC1yc2EAAAADAQABAAABAQCm2hI3Y33K1GVbdQV0lfkm/klZRJS7Kcz8+53e/BoIbVMFH0jqm1aejELDFgPnN7HvIZ/csYGzF/ssTx5lXVaHQh/qkYwfqQBg8WvXVB0Jmogj1hr6z5M8Qy/3oCx0fSmh6e/Ekfk8vHhiHQlGZV3o8a2AW5SkP8IH/OgT6Bq+SMuB+xtSciVBZqSLI0OgYtOZ0MyxBzfLau1Tyegu5lVFevZDVjecnIaS4l+v2VIQ/OgaZ40oAI3NuRZ2EdnLqEqFyLjasx4kcuwNzD5oaXAU6T9UsqKN2rVLMKrXXXXXXXXXXX
我在传递选项值时是否缺少某些 bash 语法!
2020 年 3 月 30 日更新 根据以下评论中的建议,我在命令中添加了 AWS ARN 角色,现在面临与以前不同的问题
代码:
customer_name='demo'
customer_name_pub_value=$(cat /home/developer/naman/dir/$customer_name.pub)
aws transfer create-user --user-name $customer_name --home-directory script-test/power-archive-ireland/$customer_name/ --server-id s-aaabbbccc --ssh-public-key-body "$customer_name_pub_value" --tags 'Key=Product,Value="demo",Key=Environment,Value=dev,Key=Contact,Value="dev.user@domain.com",Key=Service,Value="sftp"' --role "arn:aws:iam::8XXXXXXXXX2:role/customer-sftp-role"
错误
An error occurred (ValidationException) when calling the CreateUser operation: 1 validation error detected: Value 'script-test/power-archive-ireland/demo/' at 'homeDirectory' failed to satisfy constraint: Member must satisfy regular expression pattern: ^$|/.*
是的,对于最后一个错误,您应该将其作为对象列表提供:
--tags [{Key="Product", Value="demo"}, {Key="Environment", Value="dev"}, {Key="Contact", Value="dev.user@domain.com"}, {Key="Service", Value="sftp"
您可能需要将 "Key" 和 "Value" 放在引号中,甚至可能必须尝试 key:value 对(即 {"Product": "demo"} ), 但这应该是通用语法。
下面是最终运行的 CLI 命令:
变化
添加了 ROLE ARN(感谢@user1394 的建议)
通过在 --home-directory 选项之前放置 / 解决了最大的问题(糟糕的 AWS 文档 (https://docs.aws.amazon.com/cli/latest/reference/transfer/create-user.html) 及其过时的 RegEx
^$|/.*
)将损坏的 CLI 转换为基于 JSON 的 CLI 以修复最终错误(并非所有标签都能够附加到旧命令中)
#!/bin/bash
customer_name='demo'
customer_name_pub_value=$(cat /home/developer/naman/dir/$customer_name.pub)
aws transfer create-user \
--user-name $customer_name \
--server-id s-aaabbbccc \
--role "arn:aws:iam::8XXXXXXXXX2:role/customer-sftp-role" \
--ssh-public-key-body "$customer_name_pub_value" \
--home-directory /script-test/power-archive-ireland/$customer_name \
--tags '[
{"Key": "Product", "Value": "demo"},
{"Key": "Environment", "Value": "dev"},
{"Key": "Contact", "Value": "dev.user@domain.com"},
{"Key": "Service", "Value": "sftp"}
]'