Amazon Web ServicesCloud

AWS SNS 启用原始消息传输 Tips

在SNS订阅中,启用原始消息的情况

可以看到lambda接收到sqs的消息是下面的样子

2023-05-08T14:07:52.511Z	8c11bcbe-1a13-5db9-a92e-e06d1e7f14ab	INFO	{
  Records: [
    {
      messageId: '37d149eb-28ee-4cd6-9ba7-ace06b3da133',
      receiptHandle: 'AQEBa30PaJWhG1dekWKvxaqJwGRGmMVdUa9zt27IYMwI4zmTiE5hBUQaV59EosWRQIR/FowT9s7L+W8YNokKeNmCr5QwZJVKaLQMhnzMZsEQybLaaXntTC1YP7vt3+2yCB5f+OEU94/bFiO2VOMlzJTUq3m39Oq9AjGW5ngBZVxvG4zLC0SberNMKQZtyoTHzyHlKezx+qedTkOW+PWH7SYtemsq3870kNRrCDpnRn7DHPTpos3PLl3ghB6Pej83aHrBYH/wGM5UkWT2DEPGF7PEc6IwCOp9JrBPL0I4db1Y5Qg=',
      body: '{"test":"123"}',
      attributes: [Object],
      messageAttributes: {},
      md5OfBody: '6602ff3f63629cfaaf3649d40d17457e',
      eventSource: 'aws:sqs',
      eventSourceARN: 'arn:aws:sqs:ap-northeast-1:sqs_test.fifo',
      awsRegion: 'ap-northeast-1'
    }
  ]
}

在SNS订阅中,不启用原始消息的情况

可以看到lambda函数接收到sqs的消息是下面的样子

2023-05-08T14:02:18.946Z	61e1cd0b-6c56-503f-a73b-91d86f4c868d	INFO	{
  Records: [
    {
      messageId: '53dda9ca-0acc-43b2-b0fc-2aba9e715081',
      receiptHandle: 'AQEBLrBZ0rLiCN+yxnkiWveLqB/W0K5PEuWEB+1fnO5RkURseXDVMRfnu+yyWuP98L4JO/tp63vjSN/Whc9/A3iO+MBGg2USMW5NAcme8RwhrLymSxf3nzLwogckJ4B4CnqyuMdNJXlsa0l4o8+mre7lGN/KQ72JIAMoWlPHj7SFzPogMuY1xTiQHuWTK8fM0+xX+2nptyMrkaZzd9f8MjXxPRkce7YF6cwb5v57shKLuabQiY6FhoKYPmO4q24Q5AMeln+CLHAu0oCsFlf+mBqoWmxmHRdJkNEiGlnTuTLQbW8=',
      body: '{\n' +
        '  "Type" : "Notification",\n' +
        '  "MessageId" : "de255c8e-f080-5231-b137-005df3aa440c",\n' +
        '  "SequenceNumber" : "10000000000000056000",\n' +
        '  "TopicArn" : "arn:aws:sns:ap-northeast-1:sns_test.fifo",\n' +
        '  "Subject" : "xxxxxx",\n' +
        '  "Message" : "{\\"test\\":\\"123\\"}",\n' +
        '  "Timestamp" : "2023-05-08T14:02:18.416Z",\n' +
        '  "UnsubscribeURL" : "https://sns.ap-northeast-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:ap-northeast-1:sns_test.fifo:989bdf8c-efff-4d33-b182-cba889cee2d5"\n' +
        '}',
      attributes: [Object],
      messageAttributes: {},
      md5OfBody: 'af06afcceeecbe23aed68cbb05f1545a',
      eventSource: 'aws:sqs',
      eventSourceARN: 'arn:aws:sqs:ap-northeast-1:sqs_test.fifo',
      awsRegion: 'ap-northeast-1'
    }
  ]
}