From d53339d5c112819d8d73370d4b4b30a19d5bfa96 Mon Sep 17 00:00:00 2001 From: Alexander Kudryavsky Date: Mon, 1 Feb 2021 16:59:29 +0300 Subject: [PATCH] fixed SNS MessageAttributes parsing --- src/Message.ts | 4 +++- src/attributeUtils.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Message.ts b/src/Message.ts index f8f3186..72ca5f7 100644 --- a/src/Message.ts +++ b/src/Message.ts @@ -21,6 +21,7 @@ export interface IMessageOpts { } interface SNSBody { + MessageAttributes: string; Message?: string; Subject: string; TopicArn: string; @@ -73,18 +74,19 @@ export class Message extends (EventEmitter as new() => MessageEmitter) { this._opts = opts; this.raw = opts.msg; this.body = opts.msg.Body; + this.attributes = parseMessageAttributes(opts.msg.MessageAttributes); if (opts.unwrapSns) { const unwrapped: SNSBody = JSON.parse(this.body || EMPTY_BODY); this.body = unwrapped.Message; this.subject = unwrapped.Subject; this.topicArn = unwrapped.TopicArn; + this.attributes = parseMessageAttributes(unwrapped.MessageAttributes); if (this.topicArn) { this.topicName = unwrapped.TopicArn.substr(unwrapped.TopicArn.lastIndexOf(':') + 1); } } this._squiss = opts.squiss; this._handled = false; - this.attributes = parseMessageAttributes(opts.msg.MessageAttributes); this.sqsAttributes = opts.msg.Attributes || {}; this._s3Retriever = opts.s3Retriever; this._s3Retain = opts.s3Retain; diff --git a/src/attributeUtils.ts b/src/attributeUtils.ts index 95e4e87..91b009f 100644 --- a/src/attributeUtils.ts +++ b/src/attributeUtils.ts @@ -27,8 +27,8 @@ export const parseMessageAttributes = (messageAttributes: SQS.MessageBodyAttribu }; const parseAttributeValue = (unparsedAttribute: SQS.MessageAttributeValue): IMessageAttribute => { - const type = unparsedAttribute.DataType; - const stringValue = unparsedAttribute.StringValue; + const type = unparsedAttribute.DataType || unparsedAttribute.Type; + const stringValue = unparsedAttribute.StringValue || unparsedAttribute.Value; const binaryValue = unparsedAttribute.BinaryValue; switch (type) {