【问题标题】:Error parsing parameter '--parameters': Expected: '=', received: 'P'解析参数“--parameters”时出错:预期:“=”,收到:“P”
【发布时间】:2020-01-05 04:45:16
【问题描述】:

我正在使用 aws cli cloudformation。在使用 JSON 参数文件和 yml 模板时,我不断收到错误消息。我尝试使用创建堆栈更新堆栈以及更改集。

Error parsing parameter '--parameters': Expected: '=', received: 'P' for input: 
- ParameterKey: FunctionName 
  ^ 
  ParameterValue: taskaplambda 
- ParameterKey: MemorySize 
  ParameterValue: 512 
- ParameterKey: Timeout 
  ParameterValue: 5 

我的命令在哪里:

aws cloudformation update-stack --stack-name apstack --template-body file://templates/cflambdatemplate.yaml --parameters file://params/param.json

而我的 param.json 是:

[
    {
        "ParameterKey": "FunctionName",
        "ParameterValue": "taskaplambda"
    },
    {
        "ParameterKey": "MemorySize",
        "ParameterValue": 512
    },
    {
        "ParameterKey": "Timeout",
        "ParameterValue": 5
    }
]

这是我的 YAML 文件

cflambdatemplate.yaml

Transform: AWS::Serverless-2016-10-31
Resources:
  tasklambda:
    Type: AWS::Serverless::Function
    Properties:
      FunctionName: !Ref FunctionName
      Handler: lambda_function.lambda_handler
      MemorySize: !Ref MemorySize
      Role:
        Fn::GetAtt: 
          - "tasklambdarole"
          - "Arn"
      Runtime: python3.7
      Timeout: !Ref Timeout
      CodeUri: 
        Bucket: taskapbucket
        Key: apbuild/lambda_function.zip

  tasklambdarole:
    Type: "AWS::IAM::Role"
    Properties: 
      AssumeRolePolicyDocument: 
        Version: "2012-10-17"
        Statement: 
          - 
            Effect: "Allow"
            Principal: 
              Service: 
                - "lambda.amazonaws.com"
            Action: 
              - "sts:AssumeRole"
      Path: "/"
  taskPolicies: 
    Type: "AWS::IAM::Policy"
    Properties: 
      PolicyName: "root"
      PolicyDocument: 
        Version: "2012-10-17"
        Statement: 
          - 
            Effect: "Allow"
            Action: "*"
            Resource: "*"
      Roles: 
        - 
          Ref: "tasklambdarole"

Parameters:
  FunctionName:
    Type: String
    MinLength: '3'
    MaxLength: '18'
  MemorySize:
    Type: Number
    MinValue: '128'
    MaxValue: '1024'
  Timeout:
    Type: Number
    MinValue: '1'
    MaxValue: '15'

我一直在尝试各种可能性,但它一直给我一个错误。

【问题讨论】:

  • 你能把你的 yml 文件也发一下吗?
  • 我也添加了。我尝试在控制台中使用它。它工作得很好。

标签: amazon-web-services amazon-cloudformation aws-cli


【解决方案1】:

只需通过 aws CLI 创建您需要的一切:

我正在使用相同的 yaml 文件和参数的 json 模板并且没有收到任何错误。以下是我在 param.json 中所做的唯一更改:

[
    {
        "ParameterKey": "FunctionName",
        "ParameterValue": "taskaplambda"
    },
    {
        "ParameterKey": "MemorySize",
        "ParameterValue": "512"
    },
    {
        "ParameterKey": "Timeout",
        "ParameterValue": "5"
    }
]

您需要将 Number 转换为 String,这是因为 CloudFormation 参数类型不映射到 JSON 类型,因此 CLI 期望所有内容都作为字符串传递。

【讨论】:

    猜你喜欢
    • 2019-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-16
    • 2018-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多