gpt4 book ai didi

json - 通过变量将 JSON 传递给 YAML

转载 作者:行者123 更新时间:2023-12-03 07:39:20 24 4
gpt4 key购买 nike

我有一个用于创建 EventBridge 规则的 YAML 文件。该规则调用一个步骤函数,该函数接受 JSON 字符串作为输入。当我使用变量传递字符串时,AWS CloudFormation 报告错误,这似乎表明引号已从 JSON 中删除。

如何将 JSON 字符串传递到 YAML 中,以便 AWS 获取正确的 YAML?

JSON:

{"Guid1": "d8a47ae8-50c5-4d76-937f-124d353e125f"}

相关 YAML:

Parameters:
StepFunctionInput:
Description: The JSON input to use when triggering the step function.
Type: String

ScheduledRule:
Type: AWS::Events::Rule
Properties:
RoleArn: !GetAtt Role.Arn
ScheduleExpression: !Sub cron(0/${StartupIntervalMinutes} * * * ? *)
State: ENABLED
Targets:
- Arn: !Ref StepFunctionArn
Id: StepFunctionV1
Input: !Ref StepFunctionInput

AWS 错误:

JSON syntax error in input for target StepFunctionV1: [Source: (String)"{Guid1: d8a47ae8-50c5-4d76-937f-124d353e125f}"; line: 1, column: 3] (Service: AmazonCloudWatchEvents; Status Code: 400; Error Code: ValidationException; Request ID: 71520ea5-d959-495a-b89f-dbc812f78e59; Proxy: null)

将 JSON 直接放入 YAML(而不是通过变量传递)可以:

          Input: '{"Guid1": "d8a47ae8-50c5-4d76-937f-124d353e125f"}'

最佳答案

事实证明这是一个 PowerShell 问题。PowerShell 在将字符串传递到 AWS CLI 之前删除了该字符串中的双引号。为了解决这个问题,我用\转义了每个字符串 AWS documentation .

Before PowerShell sends a command to the AWS CLI, it determines if your command is interpreted using typical PowerShell or CommandLineToArgvW quoting rules. When PowerShell processes using CommandLineToArgvW, you must escape characters with a backslash \

Double quotation marks " " are called expandable strings. Variables can be passed in expandable strings. For double quoted strings you have to escape twice using ``` for each quote instead of only using a backtick. The backtick escapes the backslash, and then the backslash is used as an escape character for the CommandLineToArgvW process.

关于json - 通过变量将 JSON 传递给 YAML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73708745/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com