Skip to content

Commit 8f5cad7

Browse files
Merge pull request #82 from uvasoftware/bernardo/30
Adds logic to stop processing from failing
2 parents 5299c91 + fd405f4 commit 8f5cad7

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

lib/s3-handler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ exports.handler = async (event, context, callback) => {
3737
// sanity checks
3838
assert(bucket !== undefined, "bucket not present in s3 event");
3939
assert(key !== undefined, "key not present in s3 event");
40+
assert(key.endsWith('/') !== true, "cannot process directory");
4041

4142
console.log('processing ' + utils.internalId(bucket, key));
4243

package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scanii-lambda",
3-
"version": "2.2.0",
3+
"version": "2.3.0",
44
"description": "Uva Software's Scanii.com Lambda/SAM Integration",
55
"main": "index.js",
66
"scripts": {

tests/s3-handler.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,53 @@ describe('S3 handler tests', () => {
180180
assert(result.body.includes("bucket not present"));
181181
});
182182
});
183+
it('should fail to process a directory', async () => {
184+
185+
nock('https://api-us1.scanii.com')
186+
.post('/v2.2/files/fetch')
187+
.reply(202, Buffer.from("{\"id\":\"12356789\"}"), {"Location": "https://api-us1.scanii.com/v2.2/files/1234"});
188+
189+
await handler({
190+
"Records": [
191+
{
192+
"eventVersion": "2.0",
193+
"eventSource": "aws:s3",
194+
"awsRegion": "us-west-2",
195+
"eventTime": "2015-10-01T23:28:54.280Z",
196+
"eventName": "ObjectCreated:Put",
197+
"userIdentity": {
198+
"principalId": "AWS:principal"
199+
},
200+
"requestParameters": {
201+
"sourceIPAddress": "98.167.155.191"
202+
},
203+
"responseElements": {
204+
"x-amz-request-id": "EEC943B096DE3DF9",
205+
"x-amz-id-2": "W/myEjyXFBsOA6N0byxW0tOxMA4m1fmv9KAVcovvG0nD9W1s5aX5+Wx61tlCop8LbZAw1Nz0mnc="
206+
},
207+
"s3": {
208+
"s3SchemaVersion": "1.0",
209+
"configurationId": "948c2c1a-a028-4564-93fc-76cea7622633",
210+
"bucket": {
211+
"name": "scanii-mu",
212+
"ownerIdentity": {
213+
"principalId": "principal"
214+
},
215+
"arn": "arn:aws:s3:::scanii-mu"
216+
},
217+
"object": {
218+
"size": 519,
219+
"eTag": "aa1e5c8a6a07217c25f55aa8e96ea37a",
220+
"key": "Screen+Shot+2016-01-19+at+7.24.37+PM.png",
221+
"sequencer": "00560DC1B62F962FCD"
222+
}
223+
}
224+
}
225+
]
226+
}, {}, (error, result) => {
227+
assert(error === null, "there should be no errors");
228+
assert(result.body.includes("cannot process directory"));
229+
});
230+
});
183231
});
184232

0 commit comments

Comments
 (0)