【问题标题】:AWS Cloudformation - Property validation failure: [Value of property {/RequestParameters/MessageAttributes} does not match type {String}]AWS Cloudformation - 属性验证失败:[属性值 {/RequestParameters/MessageAttributes} 与类型 {String} 不匹配]
【发布时间】:2021-12-06 14:22:27
【问题描述】:

我一直在试图了解如何克服这个错误:

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?

【问题讨论】:

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


    【解决方案1】:

    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"}'
    

    看起来Request Parameters一直都是以JSON格式映射的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-05
      • 1970-01-01
      • 2020-06-03
      • 2019-11-02
      • 2021-04-16
      • 2021-05-31
      • 2021-10-15
      相关资源
      最近更新 更多