Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json AWS CLI-在参数上分配多个值的语法是什么_Json_Amazon Web Services_Yaml_Amazon Cloudformation_Aws Cli - Fatal编程技术网

Json AWS CLI-在参数上分配多个值的语法是什么

Json AWS CLI-在参数上分配多个值的语法是什么,json,amazon-web-services,yaml,amazon-cloudformation,aws-cli,Json,Amazon Web Services,Yaml,Amazon Cloudformation,Aws Cli,例如,我有一个要求这些参数的CF模板 ----- cftemplate.yaml ----- ... Parameters: **Subnet: Description: Subnet for the Instance Type: 'AWS::EC2::Subnet::Id' SecurityGroups: Description: Security Group for Instance Type: 'List<AWS::EC2::Security

例如,我有一个要求这些参数的CF模板

----- cftemplate.yaml -----
...
Parameters:
  **Subnet:
    Description: Subnet for the Instance
    Type: 'AWS::EC2::Subnet::Id'
  SecurityGroups: 
    Description: Security Group for Instance
    Type: 'List<AWS::EC2::SecurityGroup::Id>'**
...
Resources:
 EC2Instance:
   Type: AWS::EC2::Instance
   Properties:
...
    **SubnetId: !Ref Subnet
    SecurityGroupIds: !Ref SecurityGroups**
...
----- cftemplate.yaml -----
其中params.json包含:

----- params.json ----- 
[
        {
            "ParameterKey":"Subnet",
            "ParameterValue":"subnet-11111111"
        },
        {
            "ParameterKey":"SecurityGroups",
            "ParameterValue":"sg-111111111",
            "ParameterValue":"sg-222222222"
        } 
]
----- params.json -----

现在,我的目标是消除.json文件的使用。是否有人知道该命令的速记语法,该语法应该达到与上述命令相同的效果?在网上的文档中找不到这个。提前谢谢

命令行等价物是(为澄清,几乎没有重新格式化):

在上面,注意空格和逗号很重要

使用自己的参数和沙盒帐户验证了该命令:

aws cloudformation create-stack --stack-name StackName --template-body file://instance.yaml --parameters ParameterKey=Subnet,ParameterValue=subnet-0ae6ce0f9bbf52251 ParameterKey=SecurityGroups,ParameterValue=sg-06d2a3e9c8aa99620\\,sg-004d23d188ec1146f
这是正确的,并导致开始部署堆栈的过程:

{
    "StackId": "arn:aws:cloudformation:us-east-1:xxxxxx:stack/StackName/61fbacd0-d3b0-11ea-970a-0ad23187ddb2"
}

从cli文档中

$ aws cloudformation create-stack help

...

"--parameters" (list)

   A list of "Parameter" structures that specify input parameters for
   the stack. For more information, see the Parameter data type.

Shorthand Syntax:

   ParameterKey=string,ParameterValue=string,UsePreviousValue=boolean,ResolvedValue=string ...

JSON Syntax:

   [
     {
       "ParameterKey": "string",
       "ParameterValue": "string",
       "UsePreviousValue": true|false,
       "ResolvedValue": "string"
     }
     ...
   ]

...


列表元素之间用空格分隔。

您可能需要查看rain cli。它是由cloudformation团队开发的,比aws cli好得多


@darren你好。不确定您的意思是什么?使用以下命令:
aws cloudformation创建堆栈--stack name stack name--template bodyfile://cftemplate.yaml --参数ParameterKey=子网,ParameterValue=子网-11111111 ParameterKey=安全组,ParameterValue=sg-111111111,sg-2222222
将导致:
参数验证失败:参数参数[4]的类型无效。参数值,值:['sg-111111111','sg-222222',类型:,有效类型:
但是,我认为我们只需要找到正确的语法。取决于操作系统,您可能需要将参数用单引号或双引号括起来。@marcincool!!!你的命令行得通!我在第一次测试中犯了一个错误,因为我使用了很多参数。非常感谢您的复制。荣誉还发现这个语法也被接受:
aws cloudformation create stack--stack name StackName--template bodyfile://cftemplate.yaml --参数ParameterKey=子网,ParameterValue=子网-11111111 ParameterKey=安全组,ParameterValue='sg-111111111,sg-222222'
{
    "StackId": "arn:aws:cloudformation:us-east-1:xxxxxx:stack/StackName/61fbacd0-d3b0-11ea-970a-0ad23187ddb2"
}
$ aws cloudformation create-stack help

...

"--parameters" (list)

   A list of "Parameter" structures that specify input parameters for
   the stack. For more information, see the Parameter data type.

Shorthand Syntax:

   ParameterKey=string,ParameterValue=string,UsePreviousValue=boolean,ResolvedValue=string ...

JSON Syntax:

   [
     {
       "ParameterKey": "string",
       "ParameterValue": "string",
       "UsePreviousValue": true|false,
       "ResolvedValue": "string"
     }
     ...
   ]

...