Skip to content
v2.277.0

MessageAttribute Struct ​

A message attribute to add to the SNS message.

Example ​

ts
const topic = new sns.Topic(this, 'Topic');

// Use a field from the execution data as message.
const task1 = new tasks.SnsPublish(this, 'Publish1', {
  topic,
  integrationPattern: sfn.IntegrationPattern.REQUEST_RESPONSE,
  message: sfn.TaskInput.fromDataAt('$.state.message'),
  messageAttributes: {
    place: {
      value: sfn.JsonPath.stringAt('$.place'),
    },
    pic: {
      // BINARY must be explicitly set
      dataType: tasks.MessageAttributeDataType.BINARY,
      value: sfn.JsonPath.stringAt('$.pic'),
    },
    people: {
      value: 4,
    },
    handles: {
      value: ['@kslater', '@jjf', null, '@mfanning'],
    },
  },
});

// Combine a field from the execution data with
// a literal object.
const task2 = new tasks.SnsPublish(this, 'Publish2', {
  topic,
  message: sfn.TaskInput.fromObject({
    field1: 'somedata',
    field2: sfn.JsonPath.stringAt('$.field2'),
  }),
});
python
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")
    })
)
java
Topic topic = new Topic(this, "Topic");

// Use a field from the execution data as message.
SnsPublish task1 = SnsPublish.Builder.create(this, "Publish1")
        .topic(topic)
        .integrationPattern(IntegrationPattern.REQUEST_RESPONSE)
        .message(TaskInput.fromDataAt("$.state.message"))
        .messageAttributes(Map.of(
                "place", MessageAttribute.builder()
                        .value(JsonPath.stringAt("$.place"))
                        .build(),
                "pic", MessageAttribute.builder()
                        // BINARY must be explicitly set
                        .dataType(MessageAttributeDataType.BINARY)
                        .value(JsonPath.stringAt("$.pic"))
                        .build(),
                "people", MessageAttribute.builder()
                        .value(4)
                        .build(),
                "handles", MessageAttribute.builder()
                        .value(List.of("@kslater", "@jjf", null, "@mfanning"))
                        .build()))
        .build();

// Combine a field from the execution data with
// a literal object.
SnsPublish task2 = SnsPublish.Builder.create(this, "Publish2")
        .topic(topic)
        .message(TaskInput.fromObject(Map.of(
                "field1", "somedata",
                "field2", JsonPath.stringAt("$.field2"))))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
var topic = new Topic(this, "Topic");

// Use a field from the execution data as message.
var task1 = new SnsPublish(this, "Publish1", new SnsPublishProps {
    Topic = topic,
    IntegrationPattern = IntegrationPattern.REQUEST_RESPONSE,
    Message = TaskInput.FromDataAt("$.state.message"),
    MessageAttributes = new Dictionary<string, MessageAttribute> {
        { "place", new MessageAttribute {
            Value = JsonPath.StringAt("$.place")
        } },
        { "pic", new MessageAttribute {
            // BINARY must be explicitly set
            DataType = MessageAttributeDataType.BINARY,
            Value = JsonPath.StringAt("$.pic")
        } },
        { "people", new MessageAttribute {
            Value = 4
        } },
        { "handles", new MessageAttribute {
            Value = new [] { "@kslater", "@jjf", null, "@mfanning" }
        } }
    }
});

// Combine a field from the execution data with
// a literal object.
var task2 = new SnsPublish(this, "Publish2", new SnsPublishProps {
    Topic = topic,
    Message = TaskInput.FromObject(new Dictionary<string, object> {
        { "field1", "somedata" },
        { "field2", JsonPath.StringAt("$.field2") }
    })
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
topic := sns.NewTopic(this, jsii.String("Topic"))

// Use a field from the execution data as message.
task1 := tasks.NewSnsPublish(this, jsii.String("Publish1"), &SnsPublishProps{
	Topic: Topic,
	IntegrationPattern: sfn.IntegrationPattern_REQUEST_RESPONSE,
	Message: sfn.TaskInput_FromDataAt(jsii.String("$.state.message")),
	MessageAttributes: map[string]MessageAttribute{
		"place": &MessageAttribute{
			"value": sfn.JsonPath_stringAt(jsii.String("$.place")),
		},
		"pic": &MessageAttribute{
			// BINARY must be explicitly set
			"dataType": tasks.MessageAttributeDataType_BINARY,
			"value": sfn.JsonPath_stringAt(jsii.String("$.pic")),
		},
		"people": &MessageAttribute{
			"value": jsii.Number(4),
		},
		"handles": &MessageAttribute{
			"value": []interface{}{
				jsii.String("@kslater"),
				jsii.String("@jjf"),
				nil,
				jsii.String("@mfanning"),
			},
		},
	},
})

// Combine a field from the execution data with
// a literal object.
task2 := tasks.NewSnsPublish(this, jsii.String("Publish2"), &SnsPublishProps{
	Topic: Topic,
	Message: sfn.TaskInput_FromObject(map[string]interface{}{
		"field1": jsii.String("somedata"),
		"field2": sfn.JsonPath_stringAt(jsii.String("$.field2")),
	}),
})

Properties ​

dataTypeoptionalMessageAttributeDataTypedata_typeoptionalMessageAttributeDataTypedataTypeoptionalMessageAttributeDataTypeDataTypeoptionalMessageAttributeDataTypeDataTypeoptionalMessageAttributeDataType#
The data type for the attribute.

Default: determined by type inspection if possible, fallback is String

valueanyvalueAnyvalueObjectValueobjectValueinterface{}required#
The value of the attribute.