MessageAttribute

class aws_cdk.aws_stepfunctions_tasks.MessageAttribute(*, value, data_type=None)

Bases: object

A message attribute to add to the SNS message.

Parameters:
  • value (Any) – The value of the attribute.

  • data_type (Optional[MessageAttributeDataType]) – The data type for the attribute. Default: determined by type inspection if possible, fallback is String

See:

https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html

ExampleMetadata:

infused

Example:

topic = sns.Topic(self, "Topic")

# Use a field from the execution data as message.
task1 = tasks.SnsPublish(self, "Publish1",
    topic=topic,
    integration_pattern=sfn.IntegrationPattern.REQUEST_RESPONSE,
    message=sfn.TaskInput.from_data_at("$.state.message"),
    message_attributes={
        "place": tasks.MessageAttribute(
            value=sfn.JsonPath.string_at("$.place")
        ),
        "pic": tasks.MessageAttribute(
            # BINARY must be explicitly set
            data_type=tasks.MessageAttributeDataType.BINARY,
            value=sfn.JsonPath.string_at("$.pic")
        ),
        "people": tasks.MessageAttribute(
            value=4
        ),
        "handles": tasks.MessageAttribute(
            value=["@kslater", "@jjf", null, "@mfanning"]
        )
    }
)

# Combine a field from the execution data with
# a literal object.
task2 = tasks.SnsPublish(self, "Publish2",
    topic=topic,
    message=sfn.TaskInput.from_object({
        "field1": "somedata",
        "field2": sfn.JsonPath.string_at("$.field2")
    })
)

Attributes

data_type

The data type for the attribute.

Default:

determined by type inspection if possible, fallback is String

See:

https://docs.aws.amazon.com/sns/latest/dg/sns-message-attributes.html#SNSMessageAttributes.DataTypes

value

The value of the attribute.