如何将Step Function输入传递至SNS消息字段?(Serverless框架)
如何在Serverless框架的Step Function中将输入传递到SNS消息字段?
我正在使用Serverless框架构建一个Step Function,该函数接收输入后通过SNS发送消息。请问如何将输入传递到消息字段?以下是我的定义与尝试代码:
stepFunctions: stateMachines: hellostepfunc1: name: testermachine definition: Comment: "test machine" StartAt: SNSState States: SNSState: Type: Task InputPath: $ Resource: arn:aws:states:::sns:publish Parameters: TopicArn: Fn::GetAtt: [ MyTopic, TopicArn ] Message: {InputPath: $} End: true
你当前的写法存在错误,Message: {InputPath: $} 不是Step Functions中引用输入的正确语法。要将输入传递到SNS的Message字段,需要使用Path引用(通过$符号),而非嵌套InputPath参数。
正确的配置如下:
stepFunctions: stateMachines: hellostepfunc1: name: testermachine definition: Comment: "test machine" StartAt: SNSState States: SNSState: Type: Task Resource: arn:aws:states:::sns:publish Parameters: TopicArn: Fn::GetAtt: [ MyTopic, TopicArn ] Message: "$" End: true
说明:
InputPath: $可以省略,因为Step Functions默认的输入路径就是$(代表整个输入内容);如果需要传递输入的部分内容,再设置InputPath进行过滤。Message: "$"表示将整个Step Function的输入作为SNS消息内容发送。如果只需要传递输入中的特定字段,比如输入结构为{"content": "需要发送的消息"},可以写成Message: "$.content"。
内容的提问来源于stack exchange,提问作者Fred
相关产品推荐
相关产品推荐

