我一直在尝试了解如何克服该错误:
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/