From a2e71ca5154c442d9e330dbed1c66c3b34c680f1 Mon Sep 17 00:00:00 2001 From: Alexander Forsyth Date: Fri, 26 Feb 2021 13:41:05 -0500 Subject: [PATCH] fix(s3): bugfixing the s3 endpoint parser (#3650) * fix: allow s3 to make requests to s3 object lambda when passed into the arn --- ...fixing the s3 arn endpoint parser-759e7bbd.json | 5 +++++ lib/services/s3.js | 14 +++++++++++++- lib/services/s3util.js | 6 ++++-- package.json | 2 +- scripts/region-checker/allowlist.js | 12 ++++++------ test/services/s3.spec.js | 2 +- test/services/s3control.spec.js | 2 +- 7 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 .changes/next-release/bugfix-Bugfixing the s3 arn endpoint parser-759e7bbd.json diff --git a/.changes/next-release/bugfix-Bugfixing the s3 arn endpoint parser-759e7bbd.json b/.changes/next-release/bugfix-Bugfixing the s3 arn endpoint parser-759e7bbd.json new file mode 100644 index 0000000000..7b814914c7 --- /dev/null +++ b/.changes/next-release/bugfix-Bugfixing the s3 arn endpoint parser-759e7bbd.json @@ -0,0 +1,5 @@ +{ + "type": "bugfix", + "category": "s3", + "description": "Bugfixing the s3 arn endpoint parser" +} \ No newline at end of file diff --git a/lib/services/s3.js b/lib/services/s3.js index ef2f991be8..f26480995f 100644 --- a/lib/services/s3.js +++ b/lib/services/s3.js @@ -341,6 +341,7 @@ AWS.util.update(AWS.S3.prototype, { var accessPointArn = req.service._parsedArn; var isOutpostArn = accessPointArn.service === 's3-outposts'; + var isObjectLambdaArn = accessPointArn.service === 's3-object-lambda'; var outpostsSuffix = isOutpostArn ? '.' + accessPointArn.outpostId: ''; var serviceName = isOutpostArn ? 's3-outposts': 's3-accesspoint'; @@ -356,8 +357,19 @@ AWS.util.update(AWS.S3.prototype, { useArnRegion ? accessPointArn.region : req.service.config.region, dnsSuffix ].join('.'); - endpoint.host = endpoint.hostname; + if (isObjectLambdaArn) { + // should be in the format: "accesspoint/${accesspointName}" + var serviceName = 's3-object-lambda'; + var accesspointName = accessPointArn.resource.split('/')[1]; + endpoint.hostname = [ + accesspointName + '-' + accessPointArn.accountId, + serviceName, + useArnRegion ? accessPointArn.region : req.service.config.region, + dnsSuffix + ].join('.'); + } + endpoint.host = endpoint.hostname; var encodedArn = AWS.util.uriEscape(req.params.Bucket); var path = req.httpRequest.path; //remove the Bucket value from path diff --git a/lib/services/s3util.js b/lib/services/s3util.js index 713fe227fe..b733fadd72 100644 --- a/lib/services/s3util.js +++ b/lib/services/s3util.js @@ -18,10 +18,12 @@ var s3util = { validateArnService: function validateArnService(req) { var parsedArn = req.service._parsedArn; - if (parsedArn.service !== 's3' && parsedArn.service !== 's3-outposts') { + if (parsedArn.service !== 's3' + && parsedArn.service !== 's3-outposts' + && parsedArn.service !== 's3-object-lambda') { throw AWS.util.error(new Error(), { code: 'InvalidARN', - message: 'expect \'s3\' or \'s3-outposts\' in ARN service component' + message: 'expect \'s3\' or \'s3-outposts\' or \'s3-object-lambda\' in ARN service component' }); } }, diff --git a/package.json b/package.json index 1256a89008..894a076652 100644 --- a/package.json +++ b/package.json @@ -146,4 +146,4 @@ "helper-test": "mocha scripts/lib/test-helper.spec.js", "csm-functional-test": "mocha test/publisher/functional_test" } -} \ No newline at end of file +} diff --git a/scripts/region-checker/allowlist.js b/scripts/region-checker/allowlist.js index a3680c3c21..b20bd26e7c 100644 --- a/scripts/region-checker/allowlist.js +++ b/scripts/region-checker/allowlist.js @@ -37,13 +37,13 @@ var allowlist = { 248, 261, 267, - 630, - 632, - 751, - 762, + 642, + 644, 763, - 764, - 769 + 774, + 775, + 776, + 781 ] }; diff --git a/test/services/s3.spec.js b/test/services/s3.spec.js index f3c7708e00..3296535922 100644 --- a/test/services/s3.spec.js +++ b/test/services/s3.spec.js @@ -3487,7 +3487,7 @@ describe('AWS.S3', function() { request.send(function(err, data) { expect(err).to.exist; expect(err.name).to.equal('InvalidARN'); - expect(err.message).to.equal('expect \'s3\' or \'s3-outposts\' in ARN service component'); + expect(err.message).to.equal('expect \'s3\' or \'s3-outposts\' or \'s3-object-lambda\' in ARN service component'); done(); }); }); diff --git a/test/services/s3control.spec.js b/test/services/s3control.spec.js index 0ed2809072..c63f889bc6 100644 --- a/test/services/s3control.spec.js +++ b/test/services/s3control.spec.js @@ -139,7 +139,7 @@ describe('AWS.S3Control', function() { request.send(function(err, data) { expect(err).to.exist; expect(err.name).to.equal('InvalidARN'); - expect(err.message).to.equal('expect \'s3\' or \'s3-outposts\' in ARN service component'); + expect(err.message).to.equal('expect \'s3\' or \'s3-outposts\' or \'s3-object-lambda\' in ARN service component'); done(); }); });