From cc0190fd68e50fc6994b49c63e548ec2804ca947 Mon Sep 17 00:00:00 2001 From: ste-xx Date: Mon, 4 Jun 2018 01:55:44 +0200 Subject: [PATCH] move from s3 to sns --- index.js | 16 +++++++--------- test/s3EventData.json | 38 -------------------------------------- test/snsEventData.json | 21 +++++++++++++++++++++ test/test.js | 2 +- 4 files changed, 29 insertions(+), 48 deletions(-) delete mode 100644 test/s3EventData.json create mode 100644 test/snsEventData.json diff --git a/index.js b/index.js index ba74953..bff2145 100644 --- a/index.js +++ b/index.js @@ -4,16 +4,14 @@ let s3Api = test ? require('./test/s3ApiMock.js') : require('./s3Api.js'); exports.handler = async (event) => { let { - Records: [{ - s3: { - bucket: { - name: bucketName - }, - object: { - key: key - } + MessageAttributes: { + bucket: { + Value: bucketName + }, + key: { + Value: key } - }] + } } = event; let fbFn = { diff --git a/test/s3EventData.json b/test/s3EventData.json deleted file mode 100644 index 57dac7c..0000000 --- a/test/s3EventData.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "Records":[ - { - "eventVersion":"2.0", - "eventSource":"aws:s3", - "awsRegion":"eu-west-1", - "eventTime":"2018-05-29T20:50:43.401Z", - "eventName":"ObjectCreated:Put", - "userIdentity":{ - "principalId":"AWS:AROAJKEBUJSDJ3C2N3ZG4:BackplaneAssumeRoleSession" - }, - "requestParameters":{ - "sourceIPAddress":"52.30.110.207" - }, - "responseElements":{ - "x-amz-request-id":"426F3E3D6AEC6529", - "x-amz-id-2":"TB7f1T3sgoS5PbC2rQgp0GcQIbzwjZRv8uv0YRvVxLA8dIn7bWkQo3ALo08+bN7zQvCqptEePd0=" - }, - "s3":{ - "s3SchemaVersion":"1.0", - "configurationId":"ODNlYTY0MjQtOTY4Zi00ZjIxLTk0N2ItOTI0ZDFjOWU4OTIx", - "bucket":{ - "name":"s2t-base-s2tbucket-19xbw73dypb0s", - "ownerIdentity":{ - "principalId":"A38BAX92CCWE8X" - }, - "arn":"arn:aws:s3:::s2t-base-s2tbucket-19xbw73dypb0s" - }, - "object":{ - "key":"gcp/not-transcoded/sugr1km8s6/f423fbfb-6381-11e8-a23f-c7cbebde15f2.ogg", - "size":14763, - "eTag":"11b61bbe76bf0b9f6d43065b2d093063", - "sequencer":"005B0DBD2352F35492" - } - } - } - ] -} \ No newline at end of file diff --git a/test/snsEventData.json b/test/snsEventData.json new file mode 100644 index 0000000..3bf77ce --- /dev/null +++ b/test/snsEventData.json @@ -0,0 +1,21 @@ +{ + "Type": "Notification", + "MessageId": "38c6d7ad-31ea-5dfa-ab09-84234e60df79", + "TopicArn": "arn:aws:sns:eu-west-1:029902516270:s2t-base-s2tNewFile-1SSWKUD35MW0J", + "Message": "not_empty", + "Timestamp": "2018-06-03T23:44:10.678Z", + "SignatureVersion": "1", + "Signature": "dlsQQtE23X1QBzN5SqHzTiSrpGxMnNCe3Eu5fYfVS+b2Y6uLpc9E27bTKFqTBf/XuvLiKYv/gba1KF5+dZk3inxkwE82cU0kZmULVRmPgylpdcdCjVURskCYugWoI6SmRY1mN2/0hb7bdNmt4KW3hnAUWKSiqcrIQNHURn4t9WUuhCMvqarTmc9j0G5XgO4wKQCrqTYSRreHe0qHdoAoM+ab1htptqCpCUKX8cs1nfwUqf7bPttJhaxUlIIyDTDo4NbS3i+LHxO1OLbTm9BkpDJBDKXBXIPLSkLMtZhQi94b5M6XXANOFls8gCIxHZlQzdU+EsjeXdFAq2MswpCY5Q==", + "SigningCertURL": "https://sns.eu-west-1.amazonaws.com/SimpleNotificationService-eaea6120e66ea12e88dcd8bcbddca752.pem", + "UnsubscribeURL": "https://sns.eu-west-1.amazonaws.com/?Action=Unsubscribe&SubscriptionArn=arn:aws:sns:eu-west-1:029902516270:s2t-base-s2tNewFile-1SSWKUD35MW0J:fa2b8a09-b038-4c79-b49d-b0d4eb71b5d2", + "MessageAttributes": { + "bucket": { + "Type": "String", + "Value": "s2t-base-s2tbucket-19xbw73dypb0s" + }, + "key": { + "Type": "String", + "Value": "gcp/not-transcoded/sugr1km8s6/f423fbfb-6381-11e8-a23f-c7cbebde15f2.ogg" + } + } +} \ No newline at end of file diff --git a/test/test.js b/test/test.js index d96880c..36d5b92 100644 --- a/test/test.js +++ b/test/test.js @@ -6,7 +6,7 @@ require('dotenv').config({ const expect = require('chai').expect; const fs = require('fs'); -const event = JSON.parse(fs.readFileSync('test/s3EventData.json', 'utf8')); +const event = JSON.parse(fs.readFileSync('test/snsEventData.json', 'utf8')); describe('eventhandler', () => {