1

我正在尝试在我的 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: ^$|/.*

4

2 回答 2

0

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

--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"}),但这应该是通用语法。

于 2020-03-31T14:50:26.870 回答
0

下面是最终的工作 CLI 命令:

变化

  1. 添加了 ROLE ARN(感谢@user1394 的建议)

  2. 通过在 --home-directory 选项之前放置 / 解决了最大的问题(错误的 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"}
        ]'
于 2020-03-31T18:22:23.037 回答