如何将文件内容提供为aws-cli选项值



我正试图在Linux Box中借助AWS CLI创建一个SFTP用户。

下面是我在bash脚本中传递的AWS CLI命令(我的ssh公钥在一个文件中,在变量的帮助下,我将其传递到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: ^$|/.*

是的,对于最后一个bug,您应该将其作为对象列表提供:

--tags [{Key="Product", Value="demo"}, {Key="Environment", Value="dev"}, {Key="Contact", Value="dev.user@domain.com"}, {Key="Service", Value="sftp"

您可能需要将"Key"one_answers"Value"放在引号中,甚至可能必须尝试Key:Value对(即{"Product":"demo"}(,但这应该是通用语法。

下面是最后一个可用的CLI命令:

更改

  1. 添加角色ARN(感谢@user1394的建议(

  2. 通过在主目录选项之前放置/解决了最大的问题(糟糕的AWS文档(https://docs.aws.amazon.com/cli/latest/reference/transfer/create-user.html)及其过时的RegEx^$|/.*(

  3. 将损坏的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"}
]'

相关内容

  • 没有找到相关文章

最新更新