amazon-web-services - AWS Cloudformation - 属性验证失败 : [Value of property {/RequestParameters/MessageAttributes} does not match type {String}]

标签 amazon-web-services yaml aws-cloudformation amazon-sqs aws-api-gateway

我一直在尝试了解如何克服该错误:

Property validation failure: [Value of property {/RequestParameters/MessageAttributes} does not match type {String}]

有问题的云形成资源是这样的:

 HttpApiPayloadRouteIntegration:
    Type: AWS::ApiGatewayV2::Integration
    Properties:
      ApiId: !Ref HttpApi
      Description: Proxy incoming HTTP Payload into SQS
      IntegrationType: AWS_PROXY
      IntegrationSubtype: SQS-SendMessage
      PayloadFormatVersion: "1.0"
      CredentialsArn: !GetAtt HttpApiRole.Arn
      RequestParameters:
        QueueUrl: !Ref HTTPApiEventQueue
        MessageBody: $request.body
        MessageGroupId: $request.body.repository.full_name
        MessageDeduplicationId:
          !Join [
            "-",
            [$request.body.repository.full_name, $request.body.alert.number],
          ]
        MessageAttributes:
          - firstAttribute:
              DataType: String
              StringValue: hello world
          - secondAttribute:
              DataType: String
              StringValue: goodbye world

错误发生在这里:

        MessageAttributes:
          - firstAttribute:
              DataType: String
              StringValue: hello world
          - secondAttribute:
              DataType: String
              StringValue: goodbye world

我已经尝试过:

        MessageAttributes:
          firstAttribute:
              DataType: String
              StringValue: hello world
          secondAttribute:
              DataType: String
              StringValue: goodbye world
        MessageAttributes:
          - firstAttribute:
              DataType: String
              StringValue: hello world
          - secondAttribute:
              DataType: String
              StringValue: goodbye world
        MessageAttributes:
          firstAttribute:
              Name: firstAttribute
              Type: String
              Value: hello world
          secondAttribute:
              Name: secondAttribute
              Type: String
              Value: goodbye world

我的问题是真的。如何在 yaml 云形成模板中发送 MessageAttributes?

最佳答案

AWS 文档 here 表示,在 YAML 模板中,属性 RequestParameters 像 JSON 一样进行解析。

这里是一个 YAML 模板示例:

MyIntegration:
Type: AWS::ApiGatewayV2::Integration
Properties:
  ApiId: !Ref MyApi
  Description: HTTP proxy integration
  IntegrationType: HTTP_PROXY
  IntegrationMethod: ANY
  IntegrationUri: https://api.example.com
  PayloadFormatVersion: 1.0
  RequestParameters:
    "append:header.header1": "$context.requestId"
  ResponseParameters:
    "200":
      ResponseParameters:
        - Source: "headerValue"
          Destination: "append:header.header2" 

CLI 示例:

aws apigatewayv2 create-integration \
    --api-id abcdef123 \
    --integration-subtype SQS-SendMessage \
    --integration-type AWS_PROXY \
    --payload-format-version 1.0 \
    --credentials-arn arn:aws:iam::123456789012:role/apigateway-sqs \
    --request-parameters '{"QueueUrl": "$request.header.queueUrl", "MessageBody": "$request.body.message"}'

看起来请求参数始终以JSON格式映射

关于amazon-web-services - AWS Cloudformation - 属性验证失败 : [Value of property {/RequestParameters/MessageAttributes} does not match type {String}],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69634537/

相关文章:

mysql - 在 Tableau 中将现有工作簿从 Oracle 重新指向 AWS-RDS?

amazon-web-services - 具有 s3fs 和熔断器的 Amazon S3,传输终端节点未连接

python - AWS CDK如何在网关lambda集成的请求模板中嵌入自定义java脚本

amazon-web-services - 动态更改 aws cloudformation 模板上的事件属性

amazon-web-services - 由于私有(private) IP [AWS CloudFormation],AWS 堆栈中出现循环依赖

amazon-web-services - cloudfront 指向 s3 上托管的旧版 React

amazon-web-services - 与 CodePipeline 相比,使用 AWS Amplify 托管 SPA 有什么缺点吗?

python-2.7 - Ruamel.yaml.jinja2 : typ "jinja2"not recognised on CentOS

ruby-on-rails - 在 Rails 中同步语言环境 yml 文件工具

java - SnakeYaml dump自动转换数字(表示为字符串)